参考Change directory and execute file in one command
我编写了一个简单的python shell脚本,打开终端cmd.exe,然后应该更改目录并在这个目录中运行第二个命令。
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]")
程序在第一个更改目录命令完成之前最终运行第二个命令,因此第二个命令失败。需要帮助等到第一个命令完成,并且更改目录成功,然后在更改的目录中,我需要执行第二个命令。
谢谢,非常感谢任何帮助
答案 0 :(得分:0)
尝试执行命令@ 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