【问题标题】:Powershell Script to run Python Script用于运行 Python 脚本的 Powershell 脚本
【发布时间】:2018-08-12 19:13:13
【问题描述】:

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

我需要 powershell 脚本,它会调用 python 脚本并且如果 python 返回状态为 1 应该会失败。 我不能这样做,你能帮我吗?

【问题讨论】:

    标签: python powershell scripting powershell-3.0


    【解决方案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
    

    【讨论】:

    • 非常感谢@JosefZ。它按预期工作。
    猜你喜欢
    • 1970-01-01
    • 2019-12-02
    • 1970-01-01
    • 1970-01-01
    • 2012-11-15
    • 2019-01-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多