擅长:python、mysql、java
<p>由于<code>dir</code>只是<code>cmd.exe</code>(或<code>powershell.exe</code>)理解的命令,因此您可以:</p>
<pre><code>subprocess.Popen(["cmd", "/c", "dir", "c:\\Users"], stdout=subprocess.PIPE)
</code></pre>
<p>对应于在shell中执行以下操作</p>
^{pr2}$
<p>您可能会发现您必须完全路径<code>cmd</code>,如<code>c:\\Windows\\System32\\cmd.exe</code></p>