views:

34

answers:

3

Is there an OS or user-account level modification for windows 7 that I can use to leave the console window of terminated processes open?

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.

+1  A: 

Hey,

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.

rochal
This isn't practical - doing so keeps the process alive, which affects things like file locking. Many apps aren't C#. Some are plugin-like - i.e. I don't get to control Main(). Finally, adding Console.Read() breaks the app if it's used in a pipe-line or whatever. So, where possible, I do this, but it's not usually possible.
Eamon Nerbonne
+1  A: 

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.

Preet Sangha
Sounds like a decent idea! It's not entirely ideal - this won't work from explorer or another app, for instance, but if I have detailed control of the starting parameters, this'll do!
Eamon Nerbonne
A: 

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.

RED SOFT ADAIR