I'm trying to run an iteration program, and whenever I click on it, it opens then terminates. When I open the input text file, using the program, the iteration completes, then the window instantly closes. How can I either run it so that the window does not close (and I can see my results), or manage to do the same thing in command prompt. I'm not super familiar with doing stuff in command prompt.
7 Answers
This will leave the console window open even after MyApp.exe terminates:
cmd /K "C:\SomeFolder\MyApp.exe"
You can create a shortcut with the above. This solution works with all console programs and does not require you to go through Command Prompt every time (or modify the original exe which you usually can't).
Incidentally the /K
switch has been around since NT days :-p
Another way, quite useful if the path to the .exe is a complicated one: Start the command prompt and then just drag the .exe file into the cmd window. The full path to the file will be pasted into the prompt and you just have to press enter. No need to cd into any paths.
- Open command prompt -> Got to your
.exe
's location usingcd
command -> execute your.exe
- You can add
Console.ReadKey()
at the end of your code so that program will wait until the user presses some key.
A way to run a file with cmd and have it stay open:
start /b /w /D"C:\StartAndEnd\scripts" NVIDIASystemMonitor.au3
The "/w" means it waits until the application closes.
If you are on 64bit there here is another example:
c:\windows\syswow64\cmd.exe /c c:\windows\sysnative\cmd.exe /c start /b /w /D"C:\StartAndEnd\scripts" NVIDIASystemMonitor.au3
This makes sure it still runs as 64bit.
Start menu -> cmd -> cd C:\PATHTOYOURFILE\ -> program.exe
Or add a pause function at the end of your iteration program (assuming you have access to the source)
To save the hassle of having to potentially cd into the correct folder when you're probably already there in windows explorer, simply hold shift, right click on any white space in the folder and click "Open command prompt window here" to open cmd with its directory already set. You can then just type the name of the exe itself
-
2This would best be entered as a comment, as it does not answer the original question. It is a useful tip, however. Feb 12, 2015 at 23:57
Might want to try a redirect too. I think this is so simple and also adds a persistence to the output message that is non-volatile. c:\myapp.exe > c:\myapp.dbg
cd
command, run the.exe
from there