【发布时间】:2020-05-25 02:59:38
【问题描述】:
我有一个运行命令行的python程序(Windows 10),如何将输出保存为文本文件,我也想在后台运行命令行进程。
【问题讨论】:
-
我建议检查这个问题的答案:stackoverflow.com/questions/4828885/…
标签: python windows command-line background
我有一个运行命令行的python程序(Windows 10),如何将输出保存为文本文件,我也想在后台运行命令行进程。
【问题讨论】:
标签: python windows command-line background
您只需在命令后键入> txtFile.txt 即可将命令的输出保存到文本文件中,例如:
dir > text.txt
为了让您的任务在后台运行,您应该在 python 中使用Threads。 示例:
from threading import Thread
def do_in_background():
# your background task should be here.
pass
t = Thread(target=do_in_background, daemon=True)
t.start()
【讨论】: