簡體   English   中英

如何使用python同時運行多個exe程序?

[英]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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM