0

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]?

ersran9
  • 968
  • 1
  • 8
  • 13

2 Answers2

1

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

tweet
  • 115
  • 2
  • I would have gone with that, but the code is already written and all I can do is to find something that I can do with os.system :( – ersran9 Jun 17 '12 at 07:29
  • @ersran9: The subprocess module is in the standard library. There's nothing to install, you already have it. You just need to convert the code. – Daenyth Jun 17 '12 at 16:34
0

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.

Community
  • 1
  • 1
ersran9
  • 968
  • 1
  • 8
  • 13