from contextlib import redirect_stdout
import subprocess, re, os
with open('text.txt', 'w') as f:
with redirect_stdout(f):
res = subprocess.check_output('chia plots check', shell=True, stderr=subprocess.STDOUT)
ansi_escape = re.compile(b'(?:\x1B[@-Z\\-_]|[\x80-\x9A\x9C-\x9F]|(?:\x1B\[|\x9B)[0-?]*[ -/]*[@-~])')
res = ansi_escape.sub(b'', res)
print(res.decode('utf-8'))
解决 我也有同样的问题,我找到了答案
试试这个对我有用
注意:如果要查看实时输出,必须跟踪文件
我使用python脚本解决了这个问题
我已使用redirect_stdout将输出流重定向到一个文件(所有打印都指向一个文件)。使用子流程库运行chia。由于输出包含颜色(ANSI),我使用正则表达式替换输出字节
相关问题 更多 >
编程相关推荐