【发布时间】:2018-08-12 19:13:13
【问题描述】:
我只需要使用 powershell 作为选项在 windows 环境中运行 python 脚本,因为我的 Bamboo Env 只会调用它。
我需要 powershell 脚本,它会调用 python 脚本并且如果 python 返回状态为 1 应该会失败。 我不能这样做,你能帮我吗?
【问题讨论】:
标签: python powershell scripting powershell-3.0
我只需要使用 powershell 作为选项在 windows 环境中运行 python 脚本,因为我的 Bamboo Env 只会调用它。
我需要 powershell 脚本,它会调用 python 脚本并且如果 python 返回状态为 1 应该会失败。 我不能这样做,你能帮我吗?
【问题讨论】:
标签: python powershell scripting powershell-3.0
检查$LASTEXITCODE automatic variable。
$LASTEXITCODE
包含上次运行的基于 Windows 的程序的退出代码。
一个示例 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
【讨论】: