I want to run multiple exe programs at the same time using python. Can you help me?
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!")
What happens here is that both your exes are put into separate functions, which then are run parallely using the concept of multithreading implemented via threading class of Python.
Hope it helps!
If you just want to spawn separate processes, then you can use something like
from subprocess import Popen
print(Popen(['notepad.exe']).pid)
print(Popen(['calc.exe']).pid)
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.