in reply to Re^2: Window Close / Process Termination Handler on Windows
in thread Window Close / Process Termination Handler on Windows

In that case, the parent process is not signalling your process and it dies when the parent dies. So you need to write a subroutine in C that sets a handler,
BOOL WINAPI SetConsoleCtrlHandler( _In_opt_ PHANDLER_ROUTINE HandlerRoutine, _In_ BOOL Add );
and another that is called back. The handler routine can then issue a signal of its own for your perl program to trap. It's a bit of a maze but these are the set of functions you can choose from to manage the windows console: https://docs.microsoft.com/en-us/windows/console/console-functions

Update: If you can live with uninterruptable, you could also consider a DOS wrapper that does "START /B wrapper2.bat", where wrapper2.bat runs the perl program. This should then be detached from the console window.

Replies are listed 'Best First'.
Re^4: Window Close / Process Termination Handler on Windows
by rminner (Chaplain) on Aug 29, 2018 at 16:01 UTC
    I found some initial attempt to implement SetCtrlHandler in the source of Win32::Console. It is commented out in the C part and in the perl part. So i guess the author of the Module failed to get it running and chose to not implement it. Currently it seems to boil down to either attempting to implement the given Code for SetConsoleCtrlHandler myself, or to decouple my output logic from STDOUT, so i can background the process. Sniff. Would have preferred an easier solution.