Python - 子进程和python shell

dmj*_*und 5 python subprocess popen python-idle

我试图shell到一个非python子进程,并允许它从python继承stdin和stdout. - 我正在使用subprocess.Popen

如果我从控制台调用,这可能会有效,但是当我使用python shell时它肯定不起作用

(我顺便使用IDLE)

有没有办法说服python允许非python子进程将它的stdout打印到python shell?

Tay*_*mon 6

这既适用于脚本,也适用于交互式解释器,但不适用于IDLE:

subprocess.Popen(whatever, stdin=sys.stdout, stdout=sys.stdin)
Run Code Online (Sandbox Code Playgroud)

您不能使用IDLE分配的对象sys.stdinsys.stdout参数subprocess.Popen.这些对象(IDLE shell窗口的接口)是类文件,但它们不是具有fileno属性的真实文件句柄,类Unix操作系统需要将fileno指定为子进程的stdin或stdout.我不能代表Windows,但我想它有类似的要求.