For example, I have a command commandA and want to get the the exit code after commandA is executed. CommandA is expected to be failed, so the exit code we should get is 1.
If I type command in the terminal as commandA;echo $?
, a 1 get displayed on the screen. However, when I do it with python, things went wrong.
I have tried to call commandA with os.system(commandA)
or subprocess.call(commandA.split())
, and then call os.popen('echo $?').read()
, results are 0.
os.popen('commandA;echo $?').read()
gives me a correct result but the process of commandA is not displayed in the screen, which is what I don't want it happens.