Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to prevent the console window to close when running a console application? [duplicate]

I'm creating a simple console application under Windows XP and wondering if there is a way to keep the console window open after the application is run from the Windows run prompt, without putting an endless loop at the end of main(). I want the app to behave like it was run from the run prompt after first typing cmd.

like image 441
tkyle Avatar asked Dec 13 '09 17:12

tkyle


People also ask

How do I stop my console window from closing?

You can simply press Ctrl + F5 instead of F5 to run the built code. Then it will prompt you to press any key to continue. Or you can use this line -> system("pause"); at the end of the code to make it wait until you press any key.

What allows the window to stay up when running a console app?

Keep Console Open With the Ctrl + F5 Shortcut in C# The best approach for keeping our console window open after the execution of code is to run it with the Ctrl + F5 shortcut of the Microsoft Visual Studio IDE.

How do I stop C++ console application from exiting immediately?

Before the end of your code, insert this line: system("pause"); This will keep the console until you hit a key. It also printed "Press any key to continue . . ." for me.

How do I keep the console window open in Visual Studio?

Start the project with Ctrl + F5 instead of just F5 . The console window will now stay open with the Press any key to continue . . . message after the program exits.


2 Answers

ask the user for input will stop the application flow , i think it was

string x = console.ReadLine();
like image 87
trrrrrrm Avatar answered Sep 23 '22 10:09

trrrrrrm


I think you'll need a second application which invokes the command prompt then tells it to execute your console application.

You can even do it with a single application that when called parameterless invokes the prompt and itself with a parameter that disables this behavior.

like image 27
Jader Dias Avatar answered Sep 22 '22 10:09

Jader Dias