Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

how to prevent a program from totaly terminating when its console closes

I am making a console app, and I want my program,to do some cleaning up, after you close its console
I researched a lot but I haven’t found any good answer to this

>Solution :

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

There are many ways for a process to be terminated—closing the console window is just one. In general, you cannot depend on being able to clean up on close. Alternatives are to clean-as-you-go and/or clean-up leftovers on the next launch.

If you’re worried only about the closing the console situation. Here are a couple options on Windows. Unfortunately, neither of them is trivial to implement.

  • Rather than creating a console app, create a "Windows" app that doesn’t have a GUI and instead creates its own console. When the user closes that console, the process will still be running. I cannot remember if there’s a way to attach your "Windows" program to the console it was started from. If there were, I think Visual Studio would have used that rather than the devenv.com and devenv.exe trick.

  • Create a console app that launches a second (non-console) program. The second process is your main program, but it to direct its output to the console app (e.g., using a named pipe). Likewise, the console app would have to direct user input to the second process. If the user closes the console (or the console app), the second process can continue to run.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading