Wait for batch file to finish process in Powershell before executing other commands?

断了今生、忘了曾经 提交于 2020-01-30 07:51:05

问题


I'm trying to execute a Powershell file which needs to execute batch file and once batch file processing completes then only proceed to next command And, batch process shouldn't open a new window.

$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 }

I tried above code but it's not working.


回答1:


You can use this to wait for the batch file to finish (in the same window):

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

Can you be more specific if it still doesn't work?




回答2:


Start-Process is pretty straightforward with -Wait and -NoNewWindow parameters doing what you expect. Use the `-PassThru' only to acquire an object that you need to query afterwards.

FYI & path 2>&1 would also wait for the execution with the necessary error stream redirection to the console.



来源:https://stackoverflow.com/questions/43226877/wait-for-batch-file-to-finish-process-in-powershell-before-executing-other-comma

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!