[Twisted-Python] Question on using processes

Matt Feifarek matt at dalchemy.com
Thu Aug 5 14:53:46 MDT 2004


I'm using twisted.internet.utils.getProcessOutput() to run commands from 
a reactor.

I've pretty much got this working okay (with a few false starts related 
to how args are put together... you can't send in a big long string; you 
literally have to make a list of argument words... what a PITA).

Now, I've got a command that needs to pipe something through another 
command, something like this:

/bin/cat foo.txt | /usr/bin/tail

If I set up my "process" like this:

CMD = "/bin/cat"
ARGS = [ "foo.txt", "|", "/usr/bin/tail" ]
d = utils.getProcessOutput( CMD, ARGS )

It doesn't work. Now, this is a stupidly-trivial example, but it seems 
to have trouble with thinking that the pipe symbol is a filename. My 
less trivial example merely hangs up the console and does nothing.

I figured that this had something to do with the pipe (obviously) so I 
tried going deeper and using reactor.spawnProcess...

This is a little over my head, but I tried using an instance of 
twisted.internet.protocol.ProcessProtocol as the protocol, and turning 
on usePTY. Still, no dice.

So, my next theory is that it has something to do with the way that the 
process is literally launched. This is extremely low level, and has 
resisted my attempts to figure it out even with a debugger and stepping 
through.

My question: what's the best way to go about this?

Options:
- write my own Process protocol somehow?
- figure out what child descriptors may be required to fix this?
- simply make a bash script that wraps up the pipe inside of a black box 
and make the reactor call that?

Thanks!




More information about the Twisted-Python mailing list