I've written a couple of apps that required running a command and grabbing the output, and I've found the existing interfaces problematic for this. I think the proliferation of functions and classes in the popen2 module illustrates the problem (popen2.{popen2,popen3,popen4,Popen3,Popen4}) Now if I want to read both stdout and stderr seperately then it's awkward to say the least to implement that without deadlocking using the popen2 module. Also the multiplexing of stdout and stderr in popen4 and commands.getoutput is not usually what one requires IMHO. There are external solutions like the getCommandOutput recipe: http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/52296 which has problems that I've commented on there. There are also very complex solutions like "subproc" from Ken Manheimer and "task" from Rob Hooft Therefore I bit the bullet and wrote my own, with as simple an interface as I thought possible: http://www.pixelbeat.org/libs/subProcess.py Perhaps this could be included in commands.py for e.g.? Any comments appreciated. cheers, Pádraig. p.s. sorry about the previous case of trigger finger
On Jun 24, 2004, at 3:16 PM, P@draigBrady.com wrote:
I've written a couple of apps that required running a command and grabbing the output, and I've found the existing interfaces problematic for this.
I think the proliferation of functions and classes in the popen2 module illustrates the problem (popen2.{popen2,popen3,popen4,Popen3,Popen4}) Now if I want to read both stdout and stderr seperately then it's awkward to say the least to implement that without deadlocking using the popen2 module. Also the multiplexing of stdout and stderr in popen4 and commands.getoutput is not usually what one requires IMHO.
There are external solutions like the getCommandOutput recipe: http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/52296 which has problems that I've commented on there. There are also very complex solutions like "subproc" from Ken Manheimer and "task" from Rob Hooft
Therefore I bit the bullet and wrote my own, with as simple an interface as I thought possible: http://www.pixelbeat.org/libs/subProcess.py
Perhaps this could be included in commands.py for e.g.?
There's already a PEP and implementation for a new popen-ish module that supersedes all of them and probably covers all of your needs (I've already used it in several projects and it's worked great): http://www.python.org/peps/pep-0324.html -bob
I am not Cc:ing c.l.py for fear of flooding this discussion (and also for having a thread from hell for me to summarize later =). P@draigBrady.com wrote:
I've written a couple of apps that required running a command and grabbing the output, and I've found the existing interfaces problematic for this.
I think the proliferation of functions and classes in the popen2 module illustrates the problem (popen2.{popen2,popen3,popen4,Popen3,Popen4}) Now if I want to read both stdout and stderr seperately then it's awkward to say the least to implement that without deadlocking using the popen2 module. Also the multiplexing of stdout and stderr in popen4 and commands.getoutput is not usually what one requires IMHO.
How does this compare to popen5 and PEP 324 (http://www.python.org/peps/pep-0324.html)? If it doesn't solve your problem perhaps you can work with Peter Astrand and get it rolled into the PEP so that there is a single popen replacement in development. -Brett
participants (3)
-
Bob Ippolito
-
Brett C.
-
P@draigBrady.com