I'd like to fork a subprocess in python that does not run an external command ... it would just run a defined function. And I want to capture stdout
and stderr
separately.
I know how to use os.fork()
and os.pipe()
, but that mechanism only gives me two fd's to work with. I'm looking for three fd's: one for stdin
, one for stdout
, and one for stderr
. This is easy to manage using subprocess.Popen
when running an external command, but that function doesn't seem to allow a local function to be forked; only a separate executable.
In ruby, the popen3
command can take "-" as its command argument, and in this case, a fork takes place without any external command being invoked, and the 3 fd's I mentioned are returned. Is there some sort of python analog to this routine in python?