擅长:python、mysql、java
<p>正确的解决方案可能使用注释中建议的<a href="https://docs.python.org/2/library/logging.html" rel="nofollow">^{<cd1>}</a>。</p>
<p>同时,您必须重定向<em>标准<em>输出</em>和标准<em>错误</em>流,以便将正常输出捕获为脚本报告的任何错误:</p>
<pre><code>#!/bin/sh
python recordSound.py >> logfile.log 2&>1
</code></pre>
<p>请参见<a href="http://en.wikibooks.org/wiki/Bourne_Shell_Scripting/Files_and_streams#Redirecting_standard_error_.28and_other_streams.29" rel="nofollow">one of the many web pages on that topic</a>以了解shell脚本中可用的各种重定向。</p>
<hr/>
<p>此外,如果需要在控制台上同时登录<em>和</em>实时视图,请使用<a href="http://unixhelp.ed.ac.uk/CGI/man-cgi?tee" rel="nofollow">^{<cd2>}</a>标准命令:</p>
<pre><code>#!/bin/sh
python recordSound.py 2&>1 | tee logfile.log
</code></pre>