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

编程入门 行业动态 更新时间:2024-10-10 06:18:41
本文介绍了在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.

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

更多推荐

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

本文发布于:2023-06-10 18:39:37,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/616536.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:出现错误   管道   文件   python   stdin

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!