我正在使用 CMD 执行 PowerShell 命令进行日志记录(跟踪从模拟运行更新的数据文件“trun.out”)。 > 请参阅下面代码的“调用启动 Poweshell”部分。
if %therm%==y (del /f trun.out
fsutil file createnew trun.out 8192
CALL start powershell -noninteractive -File "trun_tail_powershell.ps1"
if %dist_solve%==1 (%ans_path% -b -dis -np %num_proc% -j %job% -run %run% -i therm.inp -o trun.out) else (%ans_path% -b -dis -np %num_proc% -f -m 30000 -db 5000 -j $job -run %run% -i therm.inp -o trun.out)
REM END
)
dir
执行 if 语句后,会打开一个新的 powershell 窗口(这是故意这样做的,以便可以单独看到数据记录)。记录 trun.out 数据文件。
但是,CMD 不会在 if 语句之后立即执行“dir”命令。
我首先认为 CMD 打开一个新的 powershell 窗口进行数据记录不会将权限(不确定这是否是正确的词)返回给 CMD 以继续执行下一个命令,所以我尝试注释数据记录部分并且不创建任何 powershell 窗口。但我仍然有这个问题。它在 if 语句之后不执行任何操作。
但是如果我将“dir”命令放在 if 语句中,它将显示目录。
感谢任何帮助/指导,因为我是使用 CMD 和 powershell altogatehr 的新手。
if %therm%==y (
del /f trun.out
fsutil file createnew trun.out 8192
start /wait powershell -noninteractive -File "trun_tail_powershell.ps1"
if %dist_solve%==1 (
%ans_path% -b -dis -np %num_proc% -j %job% -run %run% -i therm.inp -o trun.out
) else (
%ans_path% -b -dis -np %num_proc% -f -m 30000 -db 5000 -j %job% -run %run% -i therm.inp -o trun.out
)
REM END
)
dir
Compo 是对的,
CALL
不应该出现在你的脚本中。当您想从脚本中调用另一个批处理文件时,应该使用它。
我认为问题在于
start
命令,您想改用 start/wait
命令。 start
命令打开一个新的cmd提示窗口,无需等待窗口关闭,但使用start/wait
,新窗口会在下一个命令执行之前关闭
我还注意到在你的 else 子句中,你有 $job 而不是 %job%
希望这有帮助。