[英]running command line programs in background using python os or subprocess module
[英]Exceptions on the Command Line Python OS Module
我目前正在弄亂Python中的OS模塊,我想做的是在命令行中捕獲異常,並引發它們。
command = input("Enter a command:")
os.system(command)
except:............How do I do this?
假設用戶輸入了無效命令,例如“ foo”。 如何捕獲異常?
您不能,不會引發異常。 您可能可以通過shell的返回碼或命令(由os.system()返回)來確定錯誤。
>>> os.system('foo')
sh: foo: not found
32512
請注意,第二行不是python的輸出。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.