【发布时间】:2012-03-18 20:03:51
【问题描述】:
我目前正在搞乱 Python 中的 OS 模块,我想做的是在命令行上捕获异常,并同时引发它们。
command = input("Enter a command:")
os.system(command)
except:............How do I do this?
假设用户输入了无效命令,例如“foo”。如何捕获异常?
【问题讨论】:
-
你真的应该使用
subprocess而不是os.system。
标签: python shell command-line