hax*_*ode 6 windows powershell wait
我有一个Windows软件包列表,我使用以下命令通过powershell安装:
& mypatch.exe /passive /norestart
mypatch.exe
正在从列表中传递,它不会等待先前的安装完成 - 它只是继续.它构建了一个巨大的安装窗口,正在等待安装.此外,我无法$LASTEXITCODE
确定安装是成功还是失败.
反正有没有让安装在开始下一个之前等待?
JesnG 使用 start-process 是正确的,但是由于问题显示传递参数,该行应该是:
Start-Process "mypatch.exe" -argumentlist "/passive /norestart" -wait
Run Code Online (Sandbox Code Playgroud)
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 $_"
}
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
10581 次 |
最近记录: |