【问题标题】:Python , trying to open a commandPython , 试图打开一个命令
【发布时间】:2014-04-02 11:58:42
【问题描述】:

我只从这里获取了简单的python代码。它是

import os
os.system("start /WAIT cmd /c {ping google.com -t }")

我的意图是,我必须打开命令提示符,然后必须 ping 谷歌。当我关闭命令提示符时程序应该停止。

但是,虽然我正在使用上面的代码命令提示符出现但自动关闭。

我不明白我必须做什么,因为我很新。

我在 Windows 7 64 位中使用 Python 2.7.6。

谢谢。

【问题讨论】:

    标签: python windows python-2.7 cmd


    【解决方案1】:

    根据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")
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2018-06-08
      • 1970-01-01
      • 1970-01-01
      • 2015-12-07
      • 1970-01-01
      • 2015-04-08
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多