Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much
 
PerlMonks  

Re^3: Window Close / Process Termination Handler on Windows

by TheloniusMonk (Sexton)
on Aug 29, 2018 at 14:51 UTC ( [id://1221308]=note: print w/replies, xml ) Need Help??


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.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1221308]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others lurking in the Monastery: (8)
As of 2024-04-23 15:38 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found