我目前有一段代码,它会按照上下文输出标准输出或标准错误流:
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?
subprocess
在Windows/Unix上的行为是不同的... - Thomas Moreau