首先中d:/start.bat;详情如下:
start cmd
编写python文件
#coding=utf-8
import subprocess
def cmd_test():
# cmd = 'cmd.exe d:/start.bat'
p = subprocess.Popen("cmd.exe /c" + "d:/start.bat", stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
curline = p.stdout.readline()
while (curline != b''):
print(curline)
curline = p.stdout.readline()
p.wait()
print(p.returncode)
if __name__ == '__main__':
cmd_test()
执行时可以打开cmd窗口;丰富.bat文件可以达到意想不到的效果,如:monkey命令的自动执行