经过更多的谷歌搜索后,我偶然发现了这个 http://www.activestate.com/blog/2007/11/supressing-
windows-error-report-messagebox-subprocess-and-
ctypes
它需要一些修补,但是下面的方法现在不会出现令人讨厌的Windows消息:)注意subprocess.Popen中的creationflags =subprocess_flags
def convert_mp3_to_wav(input_filename, output_filename): if sys.platform.startswith("win"): # Don't display the Windows GPF dialog if the invoked program dies. # See comp.os.ms-windows.programmer.win32 # How to suppress crash notification dialog?, Jan 14,2004 - # Raymond Chen's response [1] import ctypes SEM_NOGPFAULTERRORBOX = 0x0002 # From MSDN ctypes.windll.kernel32.SetErrorMode(SEM_NOGPFAULTERRORBOX); subprocess_flags = 0x8000000 #win32con.CREATE_NO_WINDOW? else: subprocess_flags = 0 """ converts the incoming mp3 file to wave file """ if not os.path.exists(input_filename): raise AudioProcessingException, "file %s does not exist" % input_filename #exec("lame {$tmpname}_o.mp3 -f {$tmpname}.mp3 && lame --depre {$tmpname}.mp3 {$tmpname}.wav"); command = ["lame", "--silent", "--depre", input_filename, output_filename] process = subprocess.Popen(command, stdout=subprocess.PIPE, stderr=subprocess.PIPE, creationflags=subprocess_flags) (stdout, stderr) = process.communicate() if process.returnpre != 0 or not os.path.exists(output_filename): raise AudioProcessingException, stdout return output_filename
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)