Reputation: 48066
Background: I like to use console programs for simple tests. These things tend to need debugging and analysis, and the easiest way to do that is to use printf
or equivalent - that's available in pretty much any language. Unfortunately, when a console program terminates, the window containing the text buffer exits - and I lose that simple feedback.
When you start a program from within Visual Studio (without debugging), however, Visual studio manages to start the program and leaves the console window open after the process terminates - that behavior is handy! Unfortunately, I can't start all processes from visual studio.
So, is there a way to start all programs or at least some programs such that their console window remains open until I close it rather than until the process exits? I'm dreaming of some really simple tool (or registry setting) to make windows a bit more suitable for simple development tasks.
Two specific cases: starting freshly compiled programs from a batch file (a simple unit test, essentially), and starting programs via explorer or some other external app (i.e. without being able to pass parameters).
Further Requirements: Ideally, any solution should work regardless of the console program started; in particular it should not depend on the language or runtime of the program, and it should not require changes to programs started or as few as possible.
In particular: I can always redirect output to a logfile, so I'm looking for something that's simpler than that; i.e. does not require maintaining filenames and managing files. Something you could use without hassle several times a minute and with multiple parallel processes. Pausing at the end of execution is a workaround that requires a code change and will break other callers of that process (since the process never terminates), so it's hardly better than logfiles and not always usable.
Upvotes: 2
Views: 1160
Reputation: 12218
For using explorer you can add a command "Run & Wait" to the explorers context menu. It doesn't require programming. This page explains how to do this in general:
http://www.petri.co.il/add_command_prompt_here_shortcut_to_windows_explorer.htm
If you run your tests from a batch file, why don't you just add a pause
statement at the end? This of course wont work if you start the tests from explorer.
Upvotes: 0
Reputation: 65496
Instead of running your program, why not execute it via a shell command like cmd.exe /K this should keep the console that your program ran around. This should work in all cases regardless of how the program is built.
Upvotes: 4
Reputation: 7781
Is it possible for you to just add Console.Read();
at the end of the program? It will keep Console window up, and will close when you press any key.
Upvotes: 1