首先我们要知道如何调用系统命令:
>>> os.system('ls')
anaconda-ks.cfg install.log.syslog 模板 图片 下载 桌面
install.log 公共的 视频 文档 音乐
0
>>>
>>> os.system('lss')
sh: lss: command not found
32512
>>>
\\第一种,我们可以肉眼识别正确的会返回0,错误的则是非0
\\第二种,使用if判断调用系统命令返回值是否为0,如为0则不输出,不为0则输出 "Without the command"
-------------------------------错误-------------------------------------
>>> if os.system('lss') !=0:print 'Without the command'
...
sh: lss: command not found
Without the command
--------------------------------正确------------------------------------
>>> if os.system('ls') !=0:print 'Without the command'
...
anaconda-ks.cfg install.log.syslog 模板 图片 下载 桌面
install.log 公共的 视频 文档 音乐
>>>
转载于:https://blog.51cto.com/ccdxdb/1707053