【问题标题】:Bad pipe filedescriptor when reading from stdin in python从python中的stdin读取时管道文件描述符错误
【发布时间】:2010-11-06 15:46:02
【问题描述】:

重复的this 问题。投票结束。

在 Windows 命令行中考虑这一点。

scriptA.py | scriptB.py

在 scriptA.py 中:

sys.stdout.write( "hello" )

在 scriptB.py 中:

print sys.stdin.read()

这会产生以下错误:

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

“关闭失败”消息似乎来自 scriptA.py 的执行。

我是否使用 sys.stdin.read()、sys.stdin.read(1)、sys.stdin.readlines() 等都没关系。

怎么了?

重复的this 问题。投票结束。

【问题讨论】:

  • 我刚用python a.py试了一下 | python b.py ,它工作正常。原因见 Johan 的回答。

标签: python windows pipe


【解决方案1】:

从文件关联开始时,stdin/stdout 重定向似乎不起作用。 这不是python特有的,而是win32 cmd.exe引起的问题。

见:http://mail.python.org/pipermail/python-bugs-list/2004-August/024920.html

【讨论】:

猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2018-02-11
  • 2023-03-06
相关资源
最近更新 更多