Simple process IO capture (Was: "shell-commands" and python!) - (0/1)

Donn Cave donn at
Mon Sep 24 06:41:04 CEST 2001

Quoth Paul Moore <gustav at>:
[ ... pipe & fork wrapper ...]

| I did some looking. The attached is a fairly simple prototype of a module for
| process handling. The simple examples
|     >>> output ="echo hello")
|     >>> print output
|     hello
|     >>> print"tr a-z A-Z", input="hello")
|     HELLO
| are similar to shell "backticks", with the ability to provide input. There are
| features to allow merging of stdout and stderr, raise an exception if the
| command fails (the default action is to continue, but make the return code
| available as process.retval()), and set teh mode of the pipe (text or binary).
| It's a fairly simple wrapper around popen2/popen4, but it seems fairly useful to
| me. Comments anyone?
| I have ideas to work on this - things like allowing a sequence of strings as the
| "command", which acts like a Unix pipe (the plumbing is messy to set up, so
| encapsulating this might be nice...) or maybe some sort of class-based interface
| (but the simplicity of the examples above is important, and should remain).
| What do people think? Is this a useful idea?

Sure!  You probably won't be surprised to hear that it has been done
a couple of times before - because on one hand, it's useful, and as
you found, it isn't really terribly hard to do.

I don't know if anyone has pushed to get something like this into the
library.  Haven't looked at yours, but since you're working with popen2,
I wonder if you could work it up to be submitted as an enhancement to
that module?

Are you thinking about reading stderr for use in the exception?
I find that very useful, but deadlock potential with two separate
input sources will make you earn your pay.

	Donn Cave, donn at

More information about the Python-list mailing list