擅长:python、mysql、java
<p>这已经得到了详细的回答。看看这篇文章,它会回答你所有的问题:
<a href="https://stackoverflow.com/questions/1818774/python-subprocess">Executing a subprocess fails</a></p>
<p>我自己也试过这个密码:</p>
<p><strong>batchtest.py</strong></p>
<pre><code>from subprocess import Popen
p = Popen("batch.bat", cwd=r"C:\Path\to\batchfolder")
stdout, stderr = p.communicate()
</code></pre>
<p><strong>批处理.bat</strong></p>
<pre><code>echo Hello World!
pause
</code></pre>
<p>我从前面的线程获得了batchtest.py示例。</p>