Python子进程.Popen管道自定义fd

我目前有这样的代码,管道stdout或stderr遵循上下文:

def execteInstruction(cmd, outputNumber):
  do_stdout = DEVNULL
  do_stderr = DEVNULL
  if outputNumber != 2:
    do_stdout = subprocess.PIPE
  else:
    do_stderr = subprocess.PIPE
  return subprocess.Popen(cmd, shell=True, stderr=do_stderr, stdout=do_stdout)

然后我用communicate()读取结果。 这工作得很好,除了我需要读取自定义fd,因为我使用子进程来运行在文件描述符26上输出的命令。

我看过写入另一个fd的代码,而不是stdout或stderr,但是没有一个从自定义fd读取。 那么我怎么能从subprocess.Popen管道自定义fd?

链接地址: http://www.djcxy.com/p/77119.html

上一篇: Python subprocess.Popen pipe custom fd

下一篇: python subprocess pipe unbuffered behaviour