我只从这里取了简单的python代码。
import os
os.system("start /WAIT cmd /c {ping google.com -t }")
我的意图是,我必须打开命令提示符,然后必须ping Google。当我关闭命令提示符时,程序应停止。
但是,当我在执行上述代码时,命令提示符出现但自动关闭。
我不太了解我必须做什么,因为我很新。
我在Windows 7 64位中使用Python 2.7.6。
谢谢你。
最佳答案
根据cmd /?
,没有提到括号。
C:\>cmd /?
Starts a new instance of the Windows command interpreter
CMD [/A | /U] [/Q] [/D] [/E:ON | /E:OFF] [/F:ON | /F:OFF] [/V:ON | /V:OFF]
[[/S] [/C | /K] string]
/C Carries out the command specified by string and then terminates
/K Carries out the command specified by string but remains
....
删除ping命令周围的括号。然后它将按预期工作。
import os
os.system("start /WAIT cmd /c ping google.com -t")