在python中从stdin读取时出现错误的管道文件描述符 [英] Bad pipe filedescriptor when reading from stdin in python

查看:169
本文介绍了在python中从stdin读取时出现错误的管道文件描述符的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

重复的这个问题.投票关闭.

Duplicate of this question. Vote to close.

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

Consider this at the windows commandline.

scriptA.py | scriptB.py

在scriptA.py中:

In scriptA.py:

sys.stdout.write( "hello" )

在scriptB.py中:

In 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.

The "close failed" message seems to come from execution of scriptA.py.

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

It doesn't matter if I use sys.stdin.read(), sys.stdin.read(1), sys.stdin.readlines() etc etc.

怎么了?

重复的这个问题.投票关闭.

Duplicate of this question. Vote to close.

推荐答案

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

It seems that stdin/stdout redirect does not work when starting from a file association. This is not specific to python, but a problem caused by win32 cmd.exe.

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

这篇关于在python中从stdin读取时出现错误的管道文件描述符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆