简体   繁体   中英

How to run a C program and get output of the program using Twisted Python

I have a Python Bot written using Twisted framework and I have a C program that outputs certain text. How would I be able to run have Twisted run the C program using a command, collect the output, then print the output back to me?

The easiest way is getProcessOutput :

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

Also see http://twistedmatrix.com/documents/current/core/howto/process.html in case you need something more complex.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM