如何访问powershell脚本';groovy中的退出代码

如何访问powershell脚本';groovy中的退出代码,powershell,groovy,Powershell,Groovy,我有一个powershell脚本,如下所示: Write-Output "Hello" Start-Sleep -s 2 exit 1 println "Hello World!" smokeTestELB() def smokeTestELB(){ println "before call" def powerShellCommand = '.\\power.ps1' def shellCommand = "powershell.exe -ExecutionPo

我有一个powershell脚本,如下所示:

Write-Output "Hello"
Start-Sleep -s 2
exit 1
println "Hello World!"

smokeTestELB()

def smokeTestELB(){
    println "before call"

    def powerShellCommand = '.\\power.ps1'
    def shellCommand = "powershell.exe -ExecutionPolicy Bypass -NoLogo -NonInteractive -NoProfile -Command \"${powerShellCommand}\""
    def process = shellCommand.execute()
    process.waitFor()

    println process.outputStream

    println "after call"
}

println "This is after powershell script has executed!"
我想访问powershell脚本在groovy文件中设置的退出代码。目前,我的groovy文件如下:

Write-Output "Hello"
Start-Sleep -s 2
exit 1
println "Hello World!"

smokeTestELB()

def smokeTestELB(){
    println "before call"

    def powerShellCommand = '.\\power.ps1'
    def shellCommand = "powershell.exe -ExecutionPolicy Bypass -NoLogo -NonInteractive -NoProfile -Command \"${powerShellCommand}\""
    def process = shellCommand.execute()
    process.waitFor()

    println process.outputStream

    println "after call"
}

println "This is after powershell script has executed!"
但是,当我尝试访问和打印
process.outputStream
时,我没有得到预期的退出代码

我的示例输出如下:

Write-Output "Hello"
Start-Sleep -s 2
exit 1
println "Hello World!"

smokeTestELB()

def smokeTestELB(){
    println "before call"

    def powerShellCommand = '.\\power.ps1'
    def shellCommand = "powershell.exe -ExecutionPolicy Bypass -NoLogo -NonInteractive -NoProfile -Command \"${powerShellCommand}\""
    def process = shellCommand.execute()
    process.waitFor()

    println process.outputStream

    println "after call"
}

println "This is after powershell script has executed!"

不确定如何将powershell的退出代码访问到我的groovy脚本中。非常感谢您的帮助


谢谢

我通过谷歌搜索找到了答案。。。感谢这里写的帖子:

基本上,您必须使用“println process.exitValue()”,它将打印出退出代码

请注意,
过程
一词专门用于此解决方案