擅长:python、mysql、java
<p>默认情况下,输入/输出是缓冲的(<a href="https://docs.python.org/3/library/subprocess.html#subprocess.Popen" rel="nofollow noreferrer">https://docs.python.org/3/library/subprocess.html#subprocess.Popen</a>)</p>
<p>您可以在<code>Popen</code>中设置<code>bufsize=0</code>:</p>
<blockquote>
<p>0 means unbuffered (read and write are one system call and can return short)</p>
</blockquote>
<p>(<a href="https://docs.python.org/3/library/subprocess.html#subprocess.Popen" rel="nofollow noreferrer">https://docs.python.org/3/library/subprocess.html#subprocess.Popen</a>)</p>
<p>或者,您可以在写入后手动刷新缓冲区:</p>
<pre class="lang-py prettyprint-override"><code>avl_ps.stdin.write(cmd)
avl_ps.stdin.flush()
</code></pre>