【问题标题】:Python command line executed the second command before completing first commandPython 命令行在完成第一个命令之前执行了第二个命令
【发布时间】:2018-07-17 09:10:12
【问题描述】:

参考Change directory and execute file in one command

我编写了一个简单的 python shell 脚本,它打开终端 cmd.exe,然后应该更改目录并在 this 目录中运行第二个命令。

os.system("start /B start cmd.exe @cmd /k cd [the directory I want to go] to && [the command I want to execute in the changed directory]")

程序在第一个更改目录命令完成之前运行第二个命令,因此第二个命令失败。需要帮助等到第一个命令完成,并且切换目录成功,然后在更改的目录中,我需要执行第二个命令。

谢谢,任何帮助将不胜感激

【问题讨论】:

    标签: python-2.7 cmd sequential cd


    【解决方案1】:

    尝试执行一个命令@time:

    import time
    
    os.system( cmd #command#1) #command for first dir
    time.spleep(3) #3 seconds delay
    os.system( cmd #command#2) #command for 2nd dir
    time.spleep(3) #3 seconds delay
    

    【讨论】:

      猜你喜欢
      • 2010-12-15
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-08-28
      • 1970-01-01
      • 2018-04-03
      相关资源
      最近更新 更多