使批处理文件等到 Perl 脚本调用的关闭命令(由批处理文件调用)被执行

Making a batch file wait until the shutdown command called by a Perl script (which is called by the batch file) gets executed

我有一个批处理文件,它调用 Perl 脚本,然后 Perl 脚本进行一些处理,然后执行命令 shutdown /r /t 1。 在Perl调用后的批处理文件中,有exit/b。例如:

批处理文件:

perl doSomething.pl

exit /b

Perl 文件:

do stuff

shutdown /r /t 1

我希望批处理文件不退出并等到关机开始。

我试过了

start /wait perl dosomething.pl

并使用任务列表循环检查 perl.exe 并仅在 perl.exe 进程完成时退出。没有任何效果。

是否有解决方案来实现此目的而不需要 'sleeping' 或无限循环等待直到关闭?

嗯,这很奇怪。它只需要与您提到的最后一个选项一起使用(检查任务列表)。

但是,我能想到的唯一选择是创建一种标志文件。让你的 perl 脚本在它终止之前的某个地方创建一个文件,让你的 bat 循环直到找到这个文件并在终止之前删除它。为了避免 "busy waiting" 你可以在你的 bat 循环中添加类似 ping localhost -n 6 >nul 的东西。