简体   繁体   English

在python中从stdin读取时出现错误的管道文件描述符

[英]Bad pipe filedescriptor when reading from stdin in python

Duplicate of this question. 这个问题重复。 Vote to close. 投票关闭。

Consider this at the windows commandline. 在Windows命令行中考虑这一点。

scriptA.py | scriptB.py

In scriptA.py: 在scriptA.py中:

sys.stdout.write( "hello" )

In scriptB.py: 在scriptB.py中:

print sys.stdin.read()

This generates the following error: 这将产生以下错误:

c:\> scriptA.py | scriptB.py
close failed: [Errno 22] Invalid argument
Traceback (most recent call last):
  File "c:\scriptB.py", line 20, in <module>
    print sys.stdin.read()
IOError: [Errno 9] Bad file descriptor

The "close failed" message seems to come from execution of scriptA.py. “关闭失败”消息似乎来自执行scriptA.py。

It doesn't matter if I use sys.stdin.read(), sys.stdin.read(1), sys.stdin.readlines() etc etc. 如果我使用sys.stdin.read(),sys.stdin.read(1),sys.stdin.readlines()等都没关系。

What's wrong? 怎么了?

Duplicate of this question. 这个问题重复。 Vote to close. 投票关闭。

It seems that stdin/stdout redirect does not work when starting from a file association. 从文件关联开始时,似乎stdin / stdout重定向不起作用。 This is not specific to python, but a problem caused by win32 cmd.exe. 这并非特定于python,而是由win32 cmd.exe引起的问题。

See: http://mail.python.org/pipermail/python-bugs-list/2004-August/024920.html 请参阅: http : //mail.python.org/pipermail/python-bugs-list/2004-August/024920.html

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM