Groovy script cannot execute external process
I'm trying to execute an external python process from my Groovy script, but it doesn't produce any output.
So, as a little sanity test, I tried to simply output the python version:
def command = """ /usr/local/bin/python -V """
def proc = command.execute()
proc.waitFor()
println "This is output: " + proc?.in?.text
The above does not give any output, however from my command line I AM it is possible to run /usr/local/bin/python -V
What's weird is if I modify the script to run identify
, then it produces output.
def command = """ /usr/local/bin/identify --version """
def proc = command.execute()
proc.waitFor()
println "This is output: " + proc?.in?.text
What could be the reason for this behavior?
source to share
python -V
prints the version number for standard error instead of standard output.
$ python -V Python 2.7.8 $ python -V 2>/dev/null $
So, to get the result, redirect stderr (2) to stdout (1):
def command = """ /usr/local/bin/python -V 2>&1 """
def proc = command.execute()
proc.waitFor()
println "This is output: " + proc?.in?.text
Alternatively, you can use err
instead in
to get standard error output:
def command = """ /usr/bin/python -V """
def proc = command.execute()
proc.waitFor()
println "This is output: " + proc?.err?.text
source to share