擅长:python、mysql、java
<p>这有点不清楚你到底想用它做什么,但是这里是helloworld使用命令行中的命令选项(-c),而不是管道。这只是运行传递的字符串,就好像它在python解释器或脚本中一样。你知道吗</p>
<pre><code>python -c "print('hello world')"
</code></pre>
<p>如果您真的想从stdin运行代码,您可以使用以下内容:</p>
<pre><code>echo "for i in range(100):\n\tprint(i)" | python -c "import sys;print('hello world');exec(''.join([item for item in sys.stdin]))"
</code></pre>
<p>手册页或<a href="https://docs.python.org/2/using/cmdline.html" rel="nofollow noreferrer">python documentation</a>中有更多关于如何使用命令行工具的内容。你知道吗</p>