同一个目录下,试用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