apache.commons.exec - 吞下执行进程抛出的异常?
我使用 Apache 的 commons exec 库在 Windows 上通过我的 java 代码运行另一个应用程序。其他应用程序(tshark)可能会抛出一个丑陋的异常,使窗口弹出“. ..“ 窗户。 有没有办法在我的java代码中吞掉该异常,这样用户就不会遇到该窗口?
I use Apache's commons exec library to run another application from my java code on windows. That other application (tshark) might throw an ugly exception which makes windows pop up "an unhandled win32 exception occured in ..." window.
Is there some way to swallow that exception in my java code, so the user won't encounter that window?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
嗯,不容易。
如果 tshark/wireshark 在您想要删除的窗口弹出时向 stderr 写入一些内容,那么您可以destroy()当您检测到 stderr 上的任何匹配字符串时,您刚刚生成的进程(这将完全摆脱 tshark/wireshark,而不仅仅是不需要的窗口)。
其他任何方法都是可行的,例如自动关闭错误窗口,但这需要更多的工作(例如使用 JNA 查找窗口标题并关闭您想要摆脱的 tshark/wireshark 异常窗口)。
Well, not easily.
If tshark/wireshark writes something to stderr when that window you want to get rid of pops up, then you may be able to destroy() the process you just spawned when you detect whatever matching string on stderr (that would get rid of tshark/wireshark entirely, not just of the unwanted window).
Anything else is doable, like automatically closing the error window, but that would require much more work (like for example using JNA to find windows title and closing the tshark/wireshark exception window you want to get rid of).