use*_*329 2 shell groovy return-value
我无法通过在 Groovy 中执行 shell 脚本获得返回码(不是输出或错误)。
对于我尝试过的所有操作,它要么要求我转义,要么只打印 $? 而不是给我 1 或 0。
groovy: 75: 美元符号后的非法字符串体字符;解决方案:要么转义文字美元符号“\$5”,要么将值表达式“${5}”@第 75 行,第 24 列括起来。
以下是我尝试过的解决方案,都不起作用。
println "../src/check_job_log.s ${it}.log".execute().text
println "Check log ${it}.log completed"
//assert ("echo \$?".execute().text == "1")
//output = """echo $?""".execute().text
println(['echo', '$?'].execute().text)
// below is code for @that other guy
//def process = "echo hello world".execute()
def process = "../src/check_job_log.s ${it}.log".execute()
print "Output: " + process.text
print "Exit code: " + process.exitValue()
Output: Exit code: 01
Run Code Online (Sandbox Code Playgroud)
使用Process.exitValue()代替(或除此之外).text:
def process = "echo hello world".execute()
print "Output: " + process.text
print "Exit code: " + process.exitValue()
Run Code Online (Sandbox Code Playgroud)