1

This question has been asked before, but there is still no answer.

The scenario is that a Java command line program is started from a Windows console window. The program is still executed when the "X" close button of the console window is pressed.

The effect is that the programm is terminated without the shutdown hooks beeing executed (they are in place and react properly on Ctrl-C).

This answer to that question suggests that it is possible to do it from C.

Is there a (possibly platform specific) library that allows to react to the closing event and use the SetConsoleCtrlHandler from Java?

Community
  • 1
  • 1
Gustave
  • 3,359
  • 4
  • 31
  • 64
  • Why should this not be closed as a duplicate of the linked question? – Jiri Tousek Mar 08 '17 at 08:53
  • @Jiri Tousek: "you cannot mark a question as a duplicate of an unanswered one." (https://stackoverflow.com/help/duplicates) – Gustave Mar 08 '17 at 09:04
  • The linked question already has three answers that are 2+ years old, but that isn't the point. What makes this question different from the linked one that warrants a new question? – Jiri Tousek Mar 08 '17 at 10:05
  • Maybe this answer is what you are looking for https://stackoverflow.com/questions/9277630/windows-shutdown-hook-on-java-application-run-from-a-bat-script#9277766 – SubOptimal Mar 08 '17 at 10:38

1 Answers1

0

maybe can use JNA to setting up a hook on windows message: WM_CLOSE, and check if it's trigger by your application window's handle.

Community
  • 1
  • 1
jay liu
  • 129
  • 8