-1

How do we check whether an os.system() function has executed properly, and if it didn't then print os.system could not work?

For example:

import os
os.system('ping 192.168.1.1')

How do we know the cmd command was executed, and how can we get its return value?

dario_ramos
  • 7,118
  • 9
  • 61
  • 108
  • `os.system` returns a exit status, `print help(os.system)`. – Ashwini Chaudhary Jan 02 '14 at 14:16
  • 1
    `os.system` passes on the return code, which is generally the indicator of these things. But you should use `subprocess` instead, unless you have a good reason not to. – wim Jan 02 '14 at 14:16

1 Answers1

1

On UNIX systems, the return value of os.system() is the status code returned by the command executed.

For Windows systems, it is little bit different and given by a specific enviroment variable, COMSPEC.

See here for more details.

Buddhima Gamlath
  • 2,318
  • 1
  • 16
  • 26