python - 用于运行 Python 脚本的 Powershell 脚本

标签 python powershell scripting powershell-3.0

我需要使用 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/

相关文章:

python - 外部合并后保留 Dataframe 列数据类型

python - 处理标签编码的未知值

powershell - 在PowerShell中的新行上拆分带有空格的字符串

windows - 从计算机名称列表中获取登录用户

linux - 如何使用 bash 获取字符串中函数的内容?

Python-3 : Why this following code returns none in print statement?

python - 在 pymongo 中使用 $natural sort - MongoDB

PowerShell HashTable - 初始化期间的自引用

c# - 如何创建一段 C#.NET 脚本让 MySql 服务器执行 MySql 脚本?

php - 从 php 脚本执行 centos 命令