Quantcast
Channel: Active questions tagged return-value - Stack Overflow
Viewing all articles
Browse latest Browse all 228

How to execute shell command in Groovy and get the return code $?

$
0
0

I can't get the return code (not the output or error) from executing a shell script within Groovy.

For all what I tried, it either asks me to escape or just print the $? instead of give me 1 or 0.

groovy: 75: illegal string body character after dollar sign;   solution: either escape a literal dollar sign "\$5" or bracket the value expression "${5}" @ line 75, column 24.

Below are solutions I tried, all don't work.

println "../src/check_job_log.s ${it}.log".execute().textprintln "Check log ${it}.log completed"//assert ("echo \$?".execute().text == "1")//output = """echo $?""".execute().textprintln(['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.textprint "Exit code: " + process.exitValue()Output: Exit code: 01

Viewing all articles
Browse latest Browse all 228

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>