使用Windows ftype和assoc机制选择正确可执行文件的任何进程I管道都缺少stdin

使用Windows ftype和assoc机制选择正确可执行文件的任何进程I管道都缺少stdin,windows,pipe,stdin,file-association,Windows,Pipe,Stdin,File Association,我在WindowsXP上。这似乎会影响任何进程,但我将使用Python3.2来演示它。“filter.py”脚本: import sys for line in sys.stdin: print(line) 像这样运行它: echo hello | filter.py Traceback (most recent call last): File "F:\Documents and Settings\jhartley\docs\projects\filtercwd\filter.

我在WindowsXP上。这似乎会影响任何进程,但我将使用Python3.2来演示它。“filter.py”脚本:

import sys
for line in sys.stdin:
    print(line)
像这样运行它:

echo hello | filter.py
Traceback (most recent call last):
  File "F:\Documents and Settings\jhartley\docs\projects\filtercwd\filter.py", line 3, in <module>
    for line in sys.stdin:
TypeError: 'NoneType' object is not iterable
echo hello | python filter.py
像这样休息:

echo hello | filter.py
Traceback (most recent call last):
  File "F:\Documents and Settings\jhartley\docs\projects\filtercwd\filter.py", line 3, in <module>
    for line in sys.stdin:
TypeError: 'NoneType' object is not iterable
echo hello | python filter.py
(通过显式调用python)工作得非常好

My.py文件通过assoc和ftype机制(Windows将使用特定程序执行的特定文件扩展名与之关联的方式)连接起来,以便使用Python执行:

(这与我的路径上最前面的“python.exe”相同)

更新:这不是Python的东西。如果创建filter.sh并使用cygwin bash运行,也会发生同样的情况。显式运行'echo hello | bash filter.sh'工作正常,但是'echo hello | filter.sh'通过assoc和ftype机制使用bash执行filter.sh,失败的原因是'/dev/stdin:没有这样的文件或目录'


所以我必须把这个显式的“python”添加到我所有的命令行中吗?另外,我很好奇它为什么会断裂。这只是我的机器的一些特性,还是其他人也看到了这一点?

你在用什么
echo
?您的路径上是否有UNIX风格的
echo
实用程序,或者您只是在使用Microsoft的实用程序(它不符合您的要求)?如果在命令提示下键入
echo on
,会发生什么情况

我在Windows 7中运行,无法复制此内容。我的路径上有一个UNIX风格的
echo
实用程序。我已经在
test.rb中编写了一个小程序:

while s = $stdin.gets
  print s
end
当我键入以下任何命令时,程序将运行:

  • test.rb
  • ruby test.rb
  • echo hello | test.rb
  • echo hello | ruby test.rb
  • 命令1和命令2的行为相同。命令3和4的行为相同。一切都如我所料

    编辑1: 以下是我运行的一些命令:

    C:\Users\David\Documents\scraps\test_ruby>ls
    test.rb
    
    C:\Users\David\Documents\scraps\test_ruby>assoc .rb
    File association not found for extension .rb
    
    C:\Users\David\Documents\scraps\test_ruby>echo hi | test.rb
    hi
    

    我对ftype了解不多,但也许你应该在你的系统上安装ruby,看看我的示例程序是否适合你。

    嘿。谢谢你的回复。我有所有的cygwin二进制文件,包括echo。也许是WindowsXP的问题。好笑,我以前没注意到。我会在其他风格的Windows上试一试,然后回来汇报。哦!我可以要求您显示将.rb文件与ruby关联的ftype和assoc设置吗?也许我用一种疯狂的方式设置了我的。i、 e.“assoc.rb”和“ftype X”的输出是什么,其中X是assoc命令的输出。谢谢我更新的答案,包括该信息。我在正常的Microsoft命令提示符下进行了实验。你用的是什么贝壳?嘿。我的shell是'cmd.exe'。如果您没有为.rb文件设置assoc,那么Windows7如何知道使用“ruby”运行“test.rb”?windows现在开始阅读hashbang行了吗?在我的test.rb中没有hashbang,所以它一定是其他东西。