voi*_*urn 3 python windows subprocess
我是一个蟒蛇新手,需要一些帮助.我正在编写一个python脚本来调用应用程序exe(比如说abc.exe).我正在使用subprocess.popen来达到这个目的.例如:
r_stdout = subprocess.Popen(CommandLine,
stdout = subprocess.PIPE,
stderr = subprocess.PIPE).communicate()[1]
Run Code Online (Sandbox Code Playgroud)
在CommandLine这里:abc.exe -options "<optionstr>".abc.exe对我来说是一个黑盒子,它正在为我传递的一些选项生成错误提示.错误提示是一个标准的Windows'提示,说abc.exe已经停止工作,给我3个选项来在线检查解决方案,关闭程序,调试程序.现在我的问题是:有没有办法避免这个命令提示符?即,是否有一种方法可以让python脚本抑制此提示?
Sam*_*mba 12
这个网站似乎有解决方案.基本上,它说在脚本开头包含这个:
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);
CREATE_NO_WINDOW = 0x08000000 # From Windows API
subprocess_flags = CREATE_NO_WINDOW
else:
subprocess_flags = 0
Run Code Online (Sandbox Code Playgroud)
在此之后,您将执行以下子进程:
r_stdout = subprocess.Popen(CommandLine,
stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
creationflags=subprocess_flags).communicate()[1]
Run Code Online (Sandbox Code Playgroud)
MSDN站点有一个页面,它定义了许多类型的创建标志.希望这可以帮助.