# -*- 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)) #执行文件