BorisHou
6/11/2018 - 2:51 AM

Python执行CMD命令

#!/usr/bin/env python
#-*-coding:utf-8-*-
#@Author : Boris Hou

import os,re,subprocess, xlwt, time, shutil
from os import listdir



def cmdRunner():
    """批量执行bat脚本,来生成XML文件"""
    cur_path = os.path.dirname(os.path.realpath(__file__))
    local_path = cur_path+'\\'
    script = cur_path+"\dontTouch.bat"
    trash = cur_path + "\\temp"
    print(trash)
    p = subprocess.Popen("cmd.exe /c" + script, stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
    curline = p.stdout.readline()
    while (curline != b''):
        print(curline)
        curline = p.stdout.readline()
    p.wait()
    print(p.returncode)
    print(u'check over')