首页 > 解决方案 > Python subprocess.Popen() 和 stdout 文件对象关联

问题描述

我想知道subprocess.Popen()对象和stdout之间的关联以及它如何将Popen实例转换为文件对象。

type(subprocess.Popen)  # <type 'type'>

subprocess.Popen(":", shell=True).__class__  # <class 'subprocess.Popen'>

type(subprocess.Popen(":", shell=True, stdout=subprocess.PIPE).stdout)  # <type 'file'>

但,

dir(subprocess.Popen)没有标准输出作为其成员

标签: pythonsubprocess

解决方案


stdout是类Popen中的一个属性,定义如下
self.stdout = None


推荐阅读