In my application, os.system is used to execute another program.
os.system('./appln')
Is there any way to detect if a runtime error occurs in the program being executed [ for example, like a SIGSEGV]?
Have a look at the subprocess
module instead of os.system
. The subprocess
module has a number of ways to capture return codes or raise exceptions on non-zero return codes: http://docs.python.org/library/subprocess.html#replacing-os-system
By checking the return values of the os.system call, it is possible to detect runtime errors in the program being executed. This question details the various return values of os.system call.
That said, it is better to follow @tweet's answer and use subprocess module instead to achieve the same.