对于我使用Windows ftype和assoc机制选择正确的可执行文件的任何
我在
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 Settingsjhartleydocsprojectsfiltercwdfilter.py",line 3,in <module> for line in sys.stdin: TypeError: 'NoneType' object is not iterable 果然,添加一个print来发现sys.stdin的值会报告它是None(和NoneType.) 或者,像这样运行它: echo hello | python filter.py (使用python的显式调用)工作完全正常. 我的.py文件被连接起来使用关联和ftype机制使用Python执行(Windows关联特定文件扩展名的方式使用特定程序执行): > assoc .py .py=Python.File > ftype Python.File Python.File="F:Python32python.exe" "%1" %* (这是我路径上最重要的’python.exe’) 更新:这不是Python的事情.如果我创建filter.sh,使用cygwin bash运行会发生同样的事情.显式运行’echo hello | bash filter.sh’工作正常,但’echo hello | filter.sh’通过assoc和ftype机制使用bash执行filter.sh,失败了’/ dev / stdin:没有这样的文件或目录’. 所以我必须将这个显式的’python’添加到我的所有命令行中?另外,我很好奇为什么它会破裂.这只是我机器的一些特点,还是其他人也看到了这个? 解决方法
你用什么回声?你的路径上是否有UNIX风格的echo实用程序,或者你只是使用了Microsoft实用程序(它没有按你想要的那样)?如果在命令提示符下键入echo,会发生什么?
我在Windows 7中运行,无法重现这一点.我的路径上有一个UNIX风格的echo实用程序.我有installed ruby 1.9.2并在test.rb中写了一个小程序: while s = $stdin.gets print s end 当我输入以下任何命令时,程序运行: > test.rb 命令1和2的行为相同.命令3和4的行为相同.一切都像我期望的那样. 编辑1: C:UsersDavidDocumentsscrapstest_ruby>ls test.rb C:UsersDavidDocumentsscrapstest_ruby>assoc .rb File association not found for extension .rb C:UsersDavidDocumentsscrapstest_ruby>echo hi | test.rb hi 我对ftype知之甚少,但也许你应该在你的系统上安装ruby,看看我的示例程序是否适合你. (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |