I want to execute a python script from a bash script, and I want to store the output of the python script in a variable.
In my python script, I print some error message with the value 0 or 1
def main ():
if condition A :
sys.stderr.write("FORBIDDEN commit")
return 1
else: return 0
sys.exit(main())
this my bash script:
I used $? to get exit code + error value from the python script
python /var/www/svn/TEST/hooks/pre-commit-standard-codeline.py $SVNRepository $SVNTransaction
PYTHONRESULT=$?
echo $PYTHONRESULT >&2 #echo display -->FORBIDDEN commit1
if [ $PYTHONRESULT -ne 0 ];
then
echo -e "\n" >&2
echo "=====================================================================" >&2
echo "Your commit is blocked for the following reasons:" >&2
echo -e "\n" >&2
echo -e ${PYTHONRESULT:0} >&2
echo -e "\n" >&2
echo "=====================================================================" >&2
echo -e "\n"
exit 1
fi
my problem is in the bash script I want to split the exit value of the python from the error message so I can trigger my results in the echo command
I tried ${PYTHONRESULT:0} but it always gives me the exit value of the python script
stderrmessage youwrite.$?, and the error message was printed to stderr (and is not stored in$?nor in$PYTHONRESULT). Maybe you're confused because they both appear on the same line when you execute your bash script?IFsys.stderr.write("FORBIDDEN commit\n")with\nat the end.