擅长:python、mysql、java
<p><a href="http://docs.python.org/library/subprocess.html" rel="noreferrer">subprocess.Popen</a>做你想做的事。</p>
<pre><code>from subprocess import Popen
p = Popen(['watch', 'ls']) # something long running
# ... do other stuff while subprocess is running
p.terminate()
</code></pre>
<p>(编辑以完成注释中的答案)</p>
<p>Popen实例可以执行其他各种操作,比如可以<a href="http://docs.python.org/library/subprocess.html#subprocess.Popen.poll" rel="noreferrer">^{<cd1>}</a>查看它是否仍在运行,也可以<a href="http://docs.python.org/library/subprocess.html#subprocess.Popen.communicate" rel="noreferrer">^{<cd2>}</a>使用它在stdin上发送数据,然后等待它终止。</p>