问题描述
我有一个python脚本,可用来运行某些bash脚本,如下所示:
npm install
我运行python脚本并像这样捕获stdout和stderr
import subprocess
for x in files:
print(f"Running process on file {x}")
subprocess(f"process {x}",shell=True).wait()
但是,奇怪的是,当我查看日志文件时,子进程的stdout / stderr在print语句之前出现:
python3 script.py &> log
有人知道这是为什么吗?仅当我在> cat log
blah blah from subprocess
Running process on file x
调用中使用.wait()
方法时才会发生这种情况。
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)