python从指定位置读取数据时出现错误,在python中从stdin读取时出现错误的管道文件描述符...

当尝试从文件关联启动时,Python脚本中使用stdin/stdout重定向会出现错误。问题源于win32cmd.exe,而不是Python本身。尝试使用sys.stdin.read()、sys.stdin.read(1)等方法时,会收到'Bad file descriptor'错误。解决办法可能涉及理解并规避Windows命令行对stdin/stdout重定向的限制。
摘要由CSDN通过智能技术生成

Duplicate of this question. Vote to close.

Consider this at the windows commandline.

scriptA.py | scriptB.py

In scriptA.py:

sys.stdout.write( "hello" )

In 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

print sys.stdin.read()

IOError: [Errno 9] Bad file descriptor

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

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

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.

This is not specific to python, but a problem caused by win32 cmd.exe.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值