在执行其他命令之前,等待批处理文件在Powershell中完成处理?

时间:2017-04-05 09:17:20

标签: windows powershell batch-file

我正在尝试执行一个需要执行批处理文件的Powershell文件,一旦批处理文件处理完成,那么只进行下一个命令而且,批处理不应该打开一个新窗口。

$p = Start-Process $dir\bin\stop.bat -Wait -Passthru
$p.WaitForExit()
if ($p.ExitCode -eq 0) {
      java "-Dtar.memoryMapped=true" -Xms8g -Xmx8g -jar oak-run-1.4.6.jar checkpoints $dir\repository\segmentstore | Out-File $log_path\log_checkpoints.txt }

我尝试了上面的代码,但它没有用。

2 个答案:

答案 0 :(得分:1)

您可以使用它来等待批处理文件完成(在同一窗口中):

start $dir\bin\stop.bat -Wait -NoNewWindow

如果它仍然不起作用,你会更具体吗?

答案 1 :(得分:0)

Start-Process非常简单,-Wait-NoNewWindow参数可以满足您的期望。使用`-PassThru'只获取后来需要查询的对象。

FYI & path 2>&1也会等待执行,并将必要的错误流重定向到控制台。