python自动运行cmd?
python编码启动cmd批处理文件(
.bat
文件),用subprocess方法可以将相应的cmd输出获取到,代码如下: #import os #os.system("c:\\sam.bat") import subprocess cmd = 'cmd.exe
c:\\sam.bat' p = subprocess.Popen("cmd.exe
/c" + "c:\\sam.bat
abc", stdout=subprocess.PIPE, stderr=subprocess.STDOUT) curline = p.stdout.readline() while(curline != b''): print(curline) curline = p.stdout.readline() p.wait() print(p.returncode)sam.bat
批处理文件代码: echo Hello world! echo show %1%