方法一:
os.system("test1.bat >> upgradelog.txt")
方法二:
p = subprocess.Popen("cmd.exe /c" + "test1.bat >> upgradelog.txt", stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
curline = p.stdout.read()
p.wait()
文章介绍了在Python中使用os.system函数和subprocess.Popen模块来执行.bat批处理文件,并将输出重定向到日志文件upgradelog.txt的两种方式。方法一是直接调用os.system,方法二是通过Popen创建子进程,并捕获输出。
方法一:
os.system("test1.bat >> upgradelog.txt")
方法二:
p = subprocess.Popen("cmd.exe /c" + "test1.bat >> upgradelog.txt", stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
curline = p.stdout.read()
p.wait()
1111
831

被折叠的 条评论
为什么被折叠?
