[英]How to run multiple exe programs at the same time using python?
我想使用python同时运行多个exe程序。 你能帮助我吗?
import os
os.system( '"C:\\Users\\FOLDER\\MLTPad1.exe"' )
os.system('"C:\\Users\\FOLDER2\\MLTPad2.exe"')
import threading
def exe1():
os.system( '"C:\\Users\\FOLDER\\MLTPad1.exe"' )
def exe2():
os.system('"C:\\Users\\FOLDER2\\MLTPad2.exe"')
if __name__ == "__main__":
# creating thread
t1 = threading.Thread(target=exe1, args=())
t2 = threading.Thread(target=exe2, args=())
# starting thread 1
t1.start()
# starting thread 2
t2.start()
# wait until thread 1 is completely executed
t1.join()
# wait until thread 2 is completely executed
t2.join()
# both threads completely executed
print("Done!")
这里发生的情况是,您的两个 exe 都被放入单独的函数中,然后使用通过 Python 的线程类实现的多线程概念并行运行。
希望能帮助到你!
如果您只想生成单独的进程,那么您可以使用类似
from subprocess import Popen
print(Popen(['notepad.exe']).pid)
print(Popen(['calc.exe']).pid)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.