展开全部
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%
#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%
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询