Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/windows/15.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/postgresql/10.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在python中从stdin读取时出现错误的管道文件描述符_Python_Windows_Pipe - Fatal编程技术网

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

在python中从stdin读取时出现错误的管道文件描述符,python,windows,pipe,Python,Windows,Pipe,问题的副本。投票结束。 在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 la

问题的副本。投票结束。

在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
c:\>scriptA.py|scriptB.py
关闭失败:[Errno 22]参数无效
回溯(最近一次呼叫最后一次):
文件“c:\scriptB.py”,第20行,在
打印sys.stdin.read()
IOError:[Errno 9]错误的文件描述符
“close failed”消息似乎来自scriptA.py的执行

不管我是否使用sys.stdin.read()、sys.stdin.read(1)、sys.stdin.readlines()等等

怎么了


问题的副本。投票关闭。

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


请参阅:

我刚刚用python a.py | python b.py进行了尝试,效果很好。请参阅Johan的答案。请考虑编辑您的响应,以便说明问题是在Windows CMD.EXE中,而不是在Python中。不确定这个问题是否真正是Windows特定的,因为我在Linux上遇到了类似的东西。请参阅我的条目,谢谢!我以为我疯了