Opening cmd.exe on Vista

I write console programs in C ++. After compilation, when I run the program from my file browser, cmd.exe closes automatically, so I can not see how my programs are displayed.

The only way I could get around this was to run the program from inside cmd.exe

Is there a way to keep cmd.exe open after the program terminates?

Is there a parameter that I can change somewhere? I do not want to run the script package with cmd.exe / K

Thanks!

[Edit] I don't know if that matters, but I'm on Vista x64

+4
source share
5 answers

Ask your application to request a keystroke before exiting - this is the easiest fix!

+6
source

You can set the shortcut using the / K switch when cmd.exe is run so that it does not end after running this command:

cmd.exe /K YourProgram.exe 
+7
source

I have always been a fan of creating a batch file that calls your program and then pauses

Prog.exe Pause

This will give a nice message "Press any key to continue ...", it is simple and does not require modification of the program.

+2
source

As the last line of your main() function, you can add this line:

 system("PAUSE"); 

Also, make sure that #include <stdlib.h> declares a system() function. This will force a console pause. However, if your program is running from inside cmd.exe , it will pause anyway, which may be undesirable.

+2
source

I know that you asked how to do this using file browsers, but in case other people are interested in the same problem, but through visual studio:

It is best to set a breakpoint right before the end of your program.

Then you can deploy your exe, and you can be sure that you will not forget to delete the input request. This is also better than an input request because it takes a long time to comment and return to the input request.

I think it’s better not to ask for input and instead run your program from a running command line.

+1
source

Source: https://habr.com/ru/post/1285876/


All Articles