擅长:python、mysql、java
<p>如果您只想<code>return 1</code>如果存在非零退出状态,请使用<code>check_call</code>,任何非零退出状态都将引发我们捕获的错误,否则<code>return 1</code>将是<code>osstdout</code>:</p>
<pre><code>import subprocess
def OSinfo(runthis):
try:
osstdout = subprocess.check_call(runthis.split())
except subprocess.CalledProcessError:
return 1
return osstdout
</code></pre>
<p>如果传递参数列表,则也不需要shell=True。</p>