用于运行Python脚本的Powershell脚本

问题描述 投票:1回答:1

我需要在Windows环境下运行一个python脚本,使用powershell作为选项,因为我的Bamboo Env只会调用它。

我需要powershell脚本,它将调用python脚本,如果python返回状态为1,则应该失败。我无法这样做,请你在这里帮助我。

python powershell scripting powershell-v3.0
1个回答
1
投票

检查$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
© www.soinside.com 2019 - 2024. All rights reserved.