Issue
I am running a shell in groovy, that executes a python script. I was able to get the out put of the python script by assigning it to a variable. However, i would like to capture Exceptions as well, but in case of exception i am unable to get the python trace. the groovy script:
script{
try{
var_name = bash("""python3 some_script.py""")
echo "$(var_name)"
}
catch(exc){
echo "$(var_name)"
}
}
in case of no exception raised from python, output from script is printed, but in case of exception in prints null. any solutions?
Solution
Python writes exceptions to standard error, hence if you want to capture them along with the normal output, you should redirect stderr to stdout by adding 2>&1
to the bash input.
In your case it would be bash("""python3 some_script.py 2>&1""")
.
I assume the bash
function sends the argument to the bash shell.
Answered By - Dzienny Answer Checked By - Katrina (WPSolving Volunteer)