我需要使用 powershell 作为选项在 Windows 环境上运行 python 脚本,因为我的 Bamboo Env 只会调用它。
我需要 powershell 脚本,它将调用 python 脚本,如果 python 返回状态为 1,则该脚本应该失败。 我无法做到这一点,请您帮我一下。
最佳答案
检查$LASTEXITCODE
automatic variable 。
$LASTEXITCODE
Contains the exit code of the last Windows-based program that was run.
示例 Powershell 脚本(应用 .
Dot sourcing operator 运行 python 脚本):
. py SomePythonScript.py
if ( $LASTEXITCODE -ne 0 ) {
Write-Warning "Exiting with code $LASTEXITCODE"
exit $LASTEXITCODE
}
### sample Powershell script continues here on `$LASTEXITCODE -eq 0` condition
关于python - 用于运行 Python 脚本的 Powershell 脚本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49105252/