同一个目录下,试用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)) #执行文件



posted @ 2022-02-11 12:00  快乐开心的大虾  阅读(859)  评论(0)    收藏  举报