【发布时间】:2020-11-16 08:03:30
【问题描述】:
因此,根据this 和this,要同时运行两个python 脚本,我应该从一个批处理文件中运行它们,并用& 分隔。
但是,这在一个简单的示例中似乎不起作用。
我目前正在尝试这个:
test1.py
import time
for i in range(5):
time.sleep(1)
print("Printing, test1:"+str(i))
test2.py
import time
for i in range(5):
time.sleep(2)
print("Printing, test2:"+str(i))
批处理文件
call "C:\Users\Username\Anaconda3\Scripts\activate.bat"
"C:\Users\Username\Anaconda3\python.exe" "C:\Users\Python\Documents\Python\Test\test1.py" &
"C:\Users\Username\Anaconda3\python.exe" "C:\Users\Python\Documents\Python\Test\test2.py" &
很明显,脚本 2 在脚本 1 之后运行。
有什么想法吗?
谢谢!
【问题讨论】:
-
您的两个链接问题显然都在谈论 Unix shell 脚本,不是 Windows 批处理文件。
-
哇.. 我没听懂。谢谢!有什么办法在 Windows 上做到这一点?
-
&在批处理文件中连接命令,因此第二个在第一个完成后运行。运行两者都使用start “” “first command”start “” “second command"。注意第一对引号是窗口标题。请参阅start /?了解更多信息
标签: python batch-file