使用 Win32::CreateProcess 时如何吞下崩溃报告
在单元测试序列中,我正在测试是否捕获数据损坏错误(故意提供损坏的数据)。
为了将程序崩溃(例如损坏的数据+糟糕的缓冲区管理)视为常规失败条件,我使用 CreateProcess 在子进程中运行程序。我的问题是,如果它崩溃,我会从 Windows 收到一个崩溃报告对话框,我必须关闭它才能继续测试序列。
有什么方法可以使用 CreateProcess 以便我可以吞下 Windows 的崩溃报告吗?
In a unittest sequence I'm testing if a data corruption error is caught or not (deliberately feeding corrupt data).
In order to treat a program crash (e.g. corrupt data + poor buffer management) as a regular fail-condition I run the program in a child process with CreateProcess. My problem is that if it crashes I get a crash report dialog from Windows and I have to close it for the test-sequence to carry on.
Is there any way of using CreateProcess so that I can swallow the crash report from Windows?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
你不能用 CreateProcess() 来做到这一点,子程序必须自己处理它。两种基本方法:
在任何一种情况下都尽量少做,你不知道程序处于什么状态是在心脏病发作的时候。最好的办法是 SetEvent() 一个命名事件并让主进程终止该进程。
You cannot do this with CreateProcess(), the child program has to take care of it itself. Two basic ways:
__try/__except
keywords to catch and handle the SEH exceptionTry to do as little as possible in either case, you have no idea what state the program is in when it suffered the heart attack. Best thing to do is to SetEvent() a named event and have your main process terminate the process.
最好的计划可能是在测试计算机上关闭 Windows 错误报告(XP 及更早版本上的 Microsoft 错误报告),至少在测试期间如此。确切的步骤取决于您的 Windows 版本,但它位于“控制面板”下。
Probably the best plan is to turn off Windows Error Reporting (Microsoft Error Reporting on XP and earlier) on your test machine, at least for the duration of the test. The exact steps depend on your Windows version, but it's under Control Panel.