擅长:python、mysql、java
<p>你使用<code>Popen</code>没有错。唯一错误的地方是您缺少<code>ssh</code>命令,并且您试图模拟的bash命令中只有两个进程时您试图运行三个进程<code>'cat - | python'</code>只是<code>ssh</code>命令的一个参数。在</p>
<p>以下命令应该更好地模拟bash命令:</p>
<pre><code>from subprocess import PIPE , Popen
p1 = Popen(["cat", "SomePythonScript.py"], stdout=PIPE)
p2 = Popen(["ssh", "remote_machine", "cat - | python"], stdin=p1.stdout, stdout=PIPE)
p1.stdout.close()
output = p2.communicate()[0]
</code></pre>