擅长:python、mysql、java
<p>您可以使用<a href="https://docs.python.org/2/library/subprocess.html#subprocess.check_call" rel="nofollow">subprocess.check_call</a>模块来运行该命令,而不需要echo来运行该命令:</p>
<pre><code>from subprocess import check_call
check_call(["./driver.exe", "bondville.dat"])
</code></pre>
<p>这相当于从bash运行<code>./driver.exe bondville.dat</code>。</p>
<p>如果要获得输出,可以使用<a href="https://docs.python.org/2/library/subprocess.html#subprocess.check_output" rel="nofollow">check_outout</a>:</p>
<pre><code>from subprocess import check_output
out = check_output(["./driver.exe", "bondville.dat"])
</code></pre>
<p>在您自己的代码中,您基本上是在回显字符串<code>command</code>,而不是实际运行命令,即<code>echo "./driver.exe bondville.dat"</code>,该命令将在shell中输出<code>./driver.exe bondville.dat</code>。</p>