From inside a bash script I try to retrieve the error code of a program launched in a new terminal window. It can be reduced to this:
#!/bin/bash
urxvt -e bash -c "exit 4"
echo $?
output: 0
I would like to access the "4" in my script that is calling urxvt. How can I do that please? :)
AFAIK graphical terminals such as uxvrt
doesn't have any utility to give you the return code of the program you've run on them.
The best and most straightforward way that came into my mind is to run a sub-shell inside your bash
( looks a little cluttered , but trust me ) and run whatever program you want inside the inner bash
and use the outer one to handle the return code as follows :
urxvt -e bash -c ' (exit 4) ; echo $? > error.code '
Now you can read the return code from the file error.code
.
Note that the existence of a temporary file is necessary since if you just echo
the return code , it gets printed in the urxvt
window which itself will get closed after a few thousands of the second.So you wouldn't get anything useful.
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments