Console app question
-
I know this is beginner-level, but how can I write a console app with Visual Studio, run the app and have the output redirected to the Visual Studio output window? If I can't do that, is there another means of pausing the application without calling a getchar() type function? bye bye, KLC
-
I know this is beginner-level, but how can I write a console app with Visual Studio, run the app and have the output redirected to the Visual Studio output window? If I can't do that, is there another means of pausing the application without calling a getchar() type function? bye bye, KLC
You can use the trace functions to get your text to the output window. System.Diagnostics.Trace I don't think there is one-line method of changing all System.Console.WriteLine's to use the output window. But you could write a class that implements/extends System.IO.TextWriter (using the Trace class as your backend) then use System.Console.SetOut, passing in an instance of your new class. HTH, James Sonork ID: 100.11138 - Hasaki
-
You can use the trace functions to get your text to the output window. System.Diagnostics.Trace I don't think there is one-line method of changing all System.Console.WriteLine's to use the output window. But you could write a class that implements/extends System.IO.TextWriter (using the Trace class as your backend) then use System.Console.SetOut, passing in an instance of your new class. HTH, James Sonork ID: 100.11138 - Hasaki
Thanks James, but both methods requires a lot of changing of code that doesn't need to be changed. I was hoping for at least a way in Visual Studio to route all Writelines to the output window. Oh well. Thanks anyway. bye bye, KLC
-
Thanks James, but both methods requires a lot of changing of code that doesn't need to be changed. I was hoping for at least a way in Visual Studio to route all Writelines to the output window. Oh well. Thanks anyway. bye bye, KLC
I didn't look into it too much when I replied (was busy putting the finishing touches on an article). Here's a class that'll do what you want :)
using System;
using System.Diagnostics;namespace ConsoleRerouter
{
/// /// Summary description for OutputToTrace.
///
public class OutputToTrace : System.IO.TextWriter
{
public OutputToTrace()
{} public override void Write(char c) { Trace.Write(c, "Console"); } public override void WriteLine(string line) { Trace.WriteLine(line, "Console"); } private System.Text.Encoding enc = new System.Text.ASCIIEncoding(); public override System.Text.Encoding Encoding { get { return enc; } } }
}
If you do anything really vigorous you'll have to add more calls to Trace.Write/WriteLine, but it'll do the deed as it is right now. Use it like
System.Console.SetOut(new ConsoleRerouter.OutputToTrace());
It worked great in my simple test (output everything that was typed in) Enjoy, James Sonork ID: 100.11138 - Hasaki -
I know this is beginner-level, but how can I write a console app with Visual Studio, run the app and have the output redirected to the Visual Studio output window? If I can't do that, is there another means of pausing the application without calling a getchar() type function? bye bye, KLC
Run the program by pressing CTRL+F5. The command-line window will request you to press a key before terminating.:-O