我有一个Windows软件包列表,通过使用以下命令在powershell中安装:
& mypatch.exe /passive /norestart
mypatch.exe
是从列表中传递的,它不会等待先前的安装完成——它只会继续进行。这会积累大量待安装的窗口。此外,我无法使用$LASTEXITCODE
来确定安装是否成功或失败。
有没有办法在开始下一个安装之前让安装程序等待?
我有一个Windows软件包列表,通过使用以下命令在powershell中安装:
& mypatch.exe /passive /norestart
mypatch.exe
是从列表中传递的,它不会等待先前的安装完成——它只会继续进行。这会积累大量待安装的窗口。此外,我无法使用$LASTEXITCODE
来确定安装是否成功或失败。
有没有办法在开始下一个安装之前让安装程序等待?
Start-Process <path to exe> -Wait
Start-Process "mypatch.exe" -argumentlist "/passive /norestart" -wait
OP还提到了如何确定安装是否成功或失败。在这种情况下,我发现使用“try, catch throw”来捕获错误状态非常有效。
try {
Start-Process "mypatch.exe" -argumentlist "/passive /norestart" -wait
} catch {
# Catch will pick up any non zero error code returned
# You can do anything you like in this block to deal with the error, examples below:
# $_ returns the error details
# This will just write the error
Write-Host "mypatch.exe returned the following error $_"
# If you want to pass the error upwards as a system error and abort your powershell script or function
Throw "Aborted mypatch.exe returned $_"
}