1

I am looking to redirect all the output from a python script to output.out, then upon completion of the python script, write Exited with code: <EXIT CODE HERE> to the same file where <EXIT CODE HERE> is the exit code of the python process/script.

I need to do this all in one line which I will be passing to a bash -c call. I can get the redirection by doing something like this:

bash -c 'python /tmp/test.py > /tmp/all.out 2>&1'

But how do I then take the exit code and write it to /tmp/all.out?

1 Answer 1

1
bash -c 'python /tmp/test.py; echo Exited with code: $?' &> /tmp/all.out

or

bash -c '(python /tmp/test.py; echo Exited with code: $?) &> /tmp/all.out'

or

bash -c 'python /tmp/test.py &> /tmp/all.out; echo Exited with code: $? &>> /tmp/all.out'

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .