SW / nologs.py
BBrother's picture
Update nologs.py
cb81b7d
raw
history blame
No virus
559 Bytes
import os
import subprocess
# 如果当前目录下有"logs.txt"文件,先删除它
try:
os.remove("logs.txt")
except FileNotFoundError:
pass
with open("logs.txt", "w") as log_file:
# 执行您的Python程序,将标准输出和标准错误重定向到/dev/null
proc = subprocess.Popen(['python', 'v2_3.py'], stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
# 循环读取标准输出并写入日志文件
for line in proc.stdout:
log_file.write(line.decode("utf-8"))
# 等待程序执行完成
proc.wait()