With many UPS in case of power failure there is the chance to start a script to be executed before shutting down the system.
In my Qt application I would like to detect some kind of event I can trigger from a batch script and start a procedure to safely stop my application (controlling some HW) before shutting down the host PC. Which is a clean way to make so? How can I listen for such "external" event from my application? and how can I trigger the event itself on Win10?
I think there is a number of options to do this like sending a signal through a TCP socket, a Windows message to a process etc... The simplest may be to simply send a kill signal to the process and handle it in your application.
To do this I would probably have a look at this: Trapping and handling taskkill in Windows Python. If you taskkill your app from your batch script, you may want to handle
WM_CLOSEorCTRL_CLOSE_EVENTas the answer explains, and then execute your cleanup code.For other Unix like OSes this would be even simpler: send one of the regular signals like SIGTERM and handle it with https://man7.org/linux/man-pages/man2/signal.2.html.