【问题标题】:How to run a C program and get output of the program using Twisted Python如何使用 Twisted Python 运行 C 程序并获取程序的输出
【发布时间】:2011-11-18 00:39:33
【问题描述】:

我有一个使用 Twisted 框架编写的 Python Bot,我有一个输出特定文本的 C 程序。如果 Twisted 使用命令运行 C​​ 程序,收集输出,然后将输出打印回给我,我将如何运行?

【问题讨论】:

    标签: python c linux twisted irc


    【解决方案1】:

    最简单的方法是getProcessOutput:

    from twisted.internet.utils import getProcessOutput
    df = getProcessOutput('ls', args=('/home','-lah'))
    df.addCallback( printOutput )
    

    如果您需要更复杂的东西,另请参阅 http://twistedmatrix.com/documents/current/core/howto/process.html

    【讨论】:

    • 一个天真的问题,但为什么要在 python 的 subprocess 模块上使用它?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-03-14
    • 1970-01-01
    • 2016-10-28
    • 2017-08-17
    • 2017-09-19
    相关资源
    最近更新 更多