问题
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