用python保存命令行输出

用python保存命令行输出,python,windows,command-line,background,Python,Windows,Command Line,Background,我有一个运行命令行(Windows 10)的python程序,如何将输出保存为文本文件,我还想在后台运行命令行进程。您只需在命令后键入>txtFile.txt即可将命令的输出保存为文本文件,如: dir > text.txt 对于要在后台运行的任务,应该在python中使用。 例如: 我建议检查一下这个问题的答案:这个答案能回答你的问题吗? from threading import Thread def do_in_background(): # your backgroun

我有一个运行命令行(Windows 10)的python程序,如何将输出保存为文本文件,我还想在后台运行命令行进程。

您只需在命令后键入
>txtFile.txt
即可将命令的输出保存为文本文件,如:

dir > text.txt
对于要在后台运行的任务,应该在python中使用。 例如:


我建议检查一下这个问题的答案:这个答案能回答你的问题吗?
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()