【问题标题】:Save command line output in python [duplicate]在python中保存命令行输出[重复]
【发布时间】:2020-05-25 02:59:38
【问题描述】:

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

【问题讨论】:

标签: python windows command-line background


【解决方案1】:

您只需在命令后键入> 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()

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2015-12-28
    • 2014-10-26
    • 2018-11-04
    • 2012-01-09
    • 2011-10-15
    • 2014-04-18
    • 2015-11-05
    相关资源
    最近更新 更多