关于Java应用程序运行Windows关机钩从蝙蝠脚本 [英] Windows shutdown hook on java application run from a bat script

查看:425
本文介绍了关于Java应用程序运行Windows关机钩从蝙蝠脚本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有它运行的Java应用程序蝙蝠脚本。如果我美元是p $ PSS CTRL + C,它的应用程序终止摆好,调用全部关闭挂钩。不过,如果我只是关闭蝙蝠脚本的cmd窗口,关机钩永远不会调用。

I have a bat script which runs a java application. If I press ctrl+c on it, it the application terminates gracefully, invoking all the shutdown hooks. However, if I just close the cmd window of the bat script, the shutdown hooks are never invoked.

有没有办法解决这个问题的方法吗?或许有一种方法来告诉蝙蝠脚本时如何关闭其窗口终止调用的应用程序?

Is there a way to solve this? Perhaps there's a way to tell the bat script how to terminate the invoked applications when its window is closed?

推荐答案

从<一个href=\"http://docs.oracle.com/javase/7/docs/api/java/lang/Runtime.html#addShutdownHook%28java.lang.Thread%29\">addShutdownHook文档:

在罕见的情况下,虚拟机可能会中止,也就是停止工作,没有干净关闭运行。当虚拟机被外部终止,例如用在Unix上SIGKILL信号或者在Microsoft Windows TerminateProcess调用发生这种情况。

In rare circumstances the virtual machine may abort, that is, stop running without shutting down cleanly. This occurs when the virtual machine is terminated externally, for example with the SIGKILL signal on Unix or the TerminateProcess call on Microsoft Windows.

因此​​,我认为没有什么在这里做,很遗憾​​。

So i think nothing to do here, unfortunately.

<一个href=\"http://msdn.microsoft.com/en-us/library/windows/desktop/ms682535%28v=vs.85%29.aspx\">CTRL-CLOSE信号在Windows控制台。似乎非可修改

CTRL-CLOSE signal in Windows Console. Seems non-tweakable.

引用上面的链接:

该系统在用户关闭控制台生成一个 CTRL + CLOSE 信号。附连到控制台的所有进程接收该信号,给每个过程的机会终止之前进行清理。当一个进程接收到这个信号,处理函数可以采取以下措施之一进行任何清理操作后:

The system generates a CTRL+CLOSE signal when the user closes a console. All processes attached to the console receive the signal, giving each process an opportunity to clean up before termination. When a process receives this signal, the handler function can take one of the following actions after performing any cleanup operations:


  • 呼叫了ExitProcess 终止进程。

  • 返回 FALSE 。如果没有注册的处理函数返回的 TRUE ,默认的处理程序将终止进程。

  • 返回 TRUE 。在这种情况下,没有其它的处理功能被调用,并且弹出对话框询问用户是否要终止进程。如果用户选择不终止的过程中,该系统不关闭控制台直到过程最后终止。

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆