Powershell - 在外部程序运行时暂停脚本

tgr*_*ger 2 powershell

我有一个powershell脚本,它完成了一些所有需要按顺序完成的事情.目前我正在使用此代码运行一些外部程序(假设我在正确的目录中)

.\program1.exe
.\program2.exe
.\program3.exe
Run Code Online (Sandbox Code Playgroud)

我遇到的问题是这些都将按顺序运行,而不是等到前一个完成.有没有办法让他们等到上一个程序结束?

And*_*ndi 5

大多数进程都会导致PowerShell等到完成,除非他们做了一些时髦的事情,比如Oracle的安装程序.

你可以尝试:

Start-Process -FilePath program1.exe -Wait

如果这不起作用,你可能会做这样的事情:

& program1.exe 
while ($true) {
    Start-Sleep -Seconds 1
    if (-not (Get-Process -Name program1 -ErrorAction SilentlyContinue)) {
        break
    }
}
"...continue here"
Run Code Online (Sandbox Code Playgroud)