2015-10-28 258 views
0

这个问题很可能在这里的某个地方,任何可以重定向我的人都会很棒。Python命令输出终端

但我无法找到它 - 很可能不能确定使用哪个适当的关键术语,因为所有东西都给我python命令行解释器。

但我只是希望能够使用python的输出作为从命令行输入到另一个程序的输入。例如:

./program `python print 'A' * 100` 

不过,我得到的错误:

python: can't open file 'print': [Errno 2] No such file or directory 

什么是做到这一点的正确方法?

+0

传递有趣的Python收集其他重定向选项,值得一读,[here](http://eli.thegreenplace.net/2015/redirecting-all-kinds-of-stdout-in-python/) –

回答

1

python可执行无开关的期望没参数(对于一个交互式shell)或* .py文件来运行

可以使用-c开关在代码

./program `python -c "print 'A' * 100"` 
0
python -c "print 'A' * 10" | ./program