python:没有外部命令的fork,并分别捕获stdout和stderr [英] python: fork without an external command, and capturing stdout and stderr separately

查看:105
本文介绍了python:没有外部命令的fork,并分别捕获stdout和stderr的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在不运行外部命令的python中派生一个子进程...它将只运行定义的函数.我想分别捕获stdoutstderr.

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.

我知道如何使用os.fork()os.pipe(),但是该机制只给了我两个fd.我正在寻找三个fd:一个用于stdin,一个用于stdout和一个用于stderr.在运行外部命令时,使用subprocess.Popen可以很容易地进行管理,但是该功能似乎不允许分叉本地功能.只是一个单独的可执行文件.

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.

在ruby中,popen3命令可以将-"作为其命令参数,在这种情况下,发生分叉而没有调用任何外部命令,并且返回了我提到的3个fd.在python中是否有某种类似于该例程的python类似物?

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?

推荐答案

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆