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