【发布时间】:2011-07-01 10:50:50
【问题描述】:
我正在从 Windows 命令提示符运行 python 脚本。它调用下面的函数,使用LAME将MP3文件转换为波形文件。
def convert_mp3_to_wav(input_filename, output_filename):
"""
converts the incoming mp3 file to wave file
"""
if not os.path.exists(input_filename):
raise AudioProcessingException, "file %s does not exist" % input_filename
command = ["lame", "--silent", "--decode", input_filename, output_filename]
process = subprocess.Popen(command, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
(stdout, stderr) = process.communicate()
if process.returncode != 0 or not os.path.exists(output_filename):
raise AudioProcessingException, stdout
return output_filename
不幸的是,LAME 总是在某些 MP3 上崩溃(并且名副其实)。 Windows“您的程序已崩溃”对话框出现,它冻结了我的脚本。一旦我关闭 Windows 对话框,就会引发 AudioProcessingException。 不必告诉 Windows 关闭,我只想让脚本引发异常,然后转到下一个 MP3。
有没有办法解决这个问题?最好通过修改脚本而不是在 Unix 上运行它。
我使用的是 Windows 7 和 Python 2.6
【问题讨论】:
-
+1 表示“最好通过修改脚本而不是在 Unix 上运行它。”
-
您是否尝试过在 Windows 中禁用错误报告?
-
呃不,我没有……我会调查的!
-
我关闭了 Windows 错误报告,但我仍然收到停止脚本运行的通知。我不确定关闭 Windows 的更多部分是否会让我的系统管理员高兴!
-
这很棘手,我找不到任何有关自己解决此问题的信息。出于兴趣,您是否尝试过使用 .wait() 而不是 .communicate()?我意识到这会锁定您的代码,直到编码完成,或者可能无法解决任何问题。只是一个测试。
标签: python subprocess