我无法从 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
Use Process.exitValue()
代替(或除了).text
:
def process = "echo hello world".execute()
print "Output: " + process.text
print "Exit code: " + process.exitValue()
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)