同一個目錄下,試用python腳本同時執行多個py腳本


# -*- coding: utf-8 -*-

"""
封裝執行shell語句方法

"""

import subprocess

import os






class Shell:
@staticmethod
def invoke(cmd):
output, errors = subprocess.Popen(cmd, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE).communicate()
o = output.decode("utf-8")
return output

if __name__ == '__main__':
lst=os.listdir(os.getcwd()) #讀取目錄
shell = Shell
for c in lst:
if os.path.isfile(c) and c.endswith('.py') and c.find("alltest")==-1: #去掉alltest.py文件
cmd = "python %s"%c
print(cmd)
print(shell.invoke(cmd)) #執行文件




免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM