views:

746

answers:

4

alt text

When doing "Console" apps in Java with Eclipse, I see the output being put in a text box on the IDE itself, instead of having a Console popping up like in Visual Studio. This comes in handy, as even after the program has exited, I can still make good use of the text that was written in it, as it doesn't get erased until I run it again. Is it possible to achieve anything like that with Visual Studio? I know that instead of doing

System.Console.WriteLine(str);

I can do

System.Diagnostics.Debug.WriteLine(str);

but it is not quite the same thing, as you get a lot of "junk" in the Output window, as all the loaded symbols and such.

Even better, is it possible to have everything done in the IDE itself, when you run your app, instead of having the Console running?

Thanks

+1  A: 

Use System.Diagnostics.Trace

Depending on what listeners you attach, trace output can go to the debug window, the console, a file, database, or all at once. The possibilities are literally endless, as implementing your own TraceListener is extremely simple.

Joel Coehoorn
Yes, but what I want to know is if it is possible to just do it, without having to implement it by myself.
devoured elysium
@devoured The Trace class outputs just to the debug window by default. You only need to attach extra listeners (and there are several already written you can use) if you want to also see the output elsewhere.
Joel Coehoorn
I went to my Debug Options dialog and chose "Redirect all Output Window text to the Immediate Window" to make the Trace output go to the Immediate window so it doesn't get all mixed up with the debug crap.
Gabe
+1  A: 

It's not totally same but read this

vittore
+1  A: 

You could create a wrapper application that you run instead of directly running your real app. The wrapper application can listen to stdout and redirect everything to Trace. Then change the run settings to launch your wrapper and pass in the path to the real app to run.

You could also have the wrapper auto-attach the debugger to the new process if a debugger is attached to the wrapper.

Sam
+1  A: 

In the Visual Studio Options Dialog -> Debugging -> Check the "Redirect All Output Window Text to the Immediate Window".

Sharpers