How do we check whether a os.system() function has executed properly if not then print "os.system could not work"

StackOverflow https://stackoverflow.com/questions/20884892

  •  23-09-2022
  •  | 
  •  

質問

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?

役に立ちましたか?

解決

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.

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top