有人能解释一下为什么这个简短的bash / python命令没有输出“hello”吗?
如果我将我的Python脚本保存到文件中,该命令会按预期工作。
在script.py文件中:
$ echo hello | python - <<END
import sys
for line in sys.stdin:
print line
END
如果我将我的Python脚本保存到文件中,该命令会按预期工作。
在script.py文件中:
import sys
for line in sys.stdin:
print line
END
$ echo "hello" | python script.py
"hello"
cat
使用方法(http://www.iki.fi/era/unix/award.html)。Shell不需要使用`cat`在进程替换中将here文档提供给Python,尽管该结构避免了绑定标准输入(Shell基本上将来自进程替换的输出作为命名临时文件可用)。 - tripleee<(< <<END ...)
,但它不起作用。 - A_bloppython <<EOF <(echo "hello")
,但是你的Python代码需要重构以读取文件参数而不是标准输入。 - tripleee