I am using a shell script to run the commands.
When running the command using this
os.popen(command).readline()
I want to get the exit code of that command.
Please let me know how we get the exit code in this case.
I am using a shell script to run the commands.
When running the command using this
os.popen(command).readline()
I want to get the exit code of that command.
Please let me know how we get the exit code in this case.
When you call close()
on the file object returned by os.popen()
, it returns the termination status if it's not 0
. You use os.waitstatus_to_exitcode()
to extract the exit code from this.
f = os.popen(command)
line = f.readline()
status = f.close()
if status:
print(os.waitstatus_to_exitcode(status))