2024-06-29 00:59:38 发布
网友
当我创建一个文件流为stderr(或stdout)的python子进程时,相应的字段是None:
stderr
stdout
None
s = subprocess.Popen(['ls','qwer'], stdout=subprocess.PIPE, stdin=subprocess.PIPE, stderr=open("zzzzz",'wb')) s.stderr is None ==> True
(我希望s.stderr是文件流)。在
s.stderr
是的,这是故意的。当您将stdout/stdin/stderrkwarg提供给^{} constructor时,您告诉它在子进程中将这些管道指向何处:
stdin
stdin, stdout and stderr specify the executed program’s standard input, standard output and standard error file handles, respectively.
但是Popen对象are documented as only having a value when you use ^{}上的stdout/stdin/stderr属性:
Popen
Popen.stdinIf the stdin argument was PIPE, this attribute is a file object that provides input to the child process. Otherwise, it is None.Popen.stdoutIf the stdout argument was PIPE, this attribute is a file object that provides output from the child process. Otherwise, it is None.Popen.stderrIf the stderr argument was PIPE, this attribute is a file object that provides error output from the child process. Otherwise, it is None.
Popen.stdin
If the stdin argument was PIPE, this attribute is a file object that provides input to the child process. Otherwise, it is None.
Popen.stdout
If the stdout argument was PIPE, this attribute is a file object that provides output from the child process. Otherwise, it is None.
Popen.stderr
If the stderr argument was PIPE, this attribute is a file object that provides error output from the child process. Otherwise, it is None.
至于为什么当你传递一个不是PIPE的句柄时Popen.std*是{},我不确定。也许是因为它被认为是多余的,因为你必须首先向构造函数传递一个打开的句柄?在
PIPE
Popen.std*
是的,这是故意的。当您将} constructor 时,您告诉它在子进程中将这些管道指向何处:
stdout
/stdin
/stderr
kwarg提供给^{但是} 上的
Popen
对象are documented as only having a value when you use ^{stdout
/stdin
/stderr
属性:至于为什么当你传递一个不是},我不确定。也许是因为它被认为是多余的,因为你必须首先向构造函数传递一个打开的句柄?在
PIPE
的句柄时Popen.std*
是{相关问题 更多 >
编程相关推荐