Presence of console application output in Visual Studio instead of console

When I run a console application in Java with Eclipse, I see that the output is placed in a text field in the IDE itself, and the console does not appear, as in Visual Studio. This is useful, because even after exiting the program, I still make good use of the text written on it, since it does not erase until I start it again. Is it possible to achieve something similar using Visual Studio? I know that instead of doing

System.Console.WriteLine(str); 

I can do

 System.Diagnostics.Debug.WriteLine(str); 

but this is not quite the same, since you get a lot of “garbage” in the “Output” window, since all the loaded characters, etc.

Even better, can everything be done in the IDE itself when you launch the application, instead of launching the console?

+97
c # visual-studio console
Mar 30 '10 at 2:57
source share
11 answers

In the Tools menu → Visual Studio Options → Debugging → check the box “Redirect the text of the entire output window to the immediate window”.

+34
Mar 31 '10 at 18:47
source share

In the Visual Studio Preferences dialog box → Debug → Move all windows of the output window to the Instant window. Then go to your project settings and change the type of “Console application” to “Windows application”. At this point, Visual Studio no longer opens a console window, and the output is redirected to the output window in Visual Studio. However, you cannot do anything “creative”, for example, to ask for a key or text, or to clear the console — you will get runtime exceptions.

+37
Mar 08 2018-12-12T00:
source share

Use System.Diagnostics.Trace

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

+4
Mar 30 '10 at 3:05
source share
+3
Mar 30 '10 at 3:14
source share

Make sure that in the debug settings window check the box " Redirect all weekends ... ":

Make sure you check

+3
Mar 29 '17 at 7:58
source share

You can create a wrapper application that you run instead of directly launching your real application. A wrapper application can listen to stdout and redirect everything to Trace. Then change the launch options to launch your shell and go along the path to the real application.

You can also force the wrapper to automatically attach the debugger to the new process if the debugger is attached to the wrapper.

+1
Mar 30 '10 at 3:25
source share

I know this is just another answer, but I thought I would write something for new web developers, which might get confused in the “Switching to a Windows application” part, because by default I put the MVC application in Visual Studio 2013 defaults to the output type of the class library.

My web application is installed by default as the class library output type. You do not need to change this. All I had to do was follow the recommendations "Tools"> "Options"> "Debug"> "Redirect all the text of the output window" to the "Immediate" window. Then I used the System.Diagnostics.Trace sentence of Joel Coehorn above.

0
Dec 04 '15 at 18:28
source share

Instead, you can collect the result from the test.

You cannot provide input, but you can easily provide several tests with different command line arguments, each of which will collect the output.

If your goal is debugging, this is a short way to suggest a repeatable debugging script.

 namespace Commandline.Test { using Microsoft.VisualStudio.TestTools.UnitTesting; [TestClass] public class CommandlineTests { [TestMethod] public void RunNoArguments() { Commandline.Program.Main(new string[0]); } } } 
0
Jan 17 '17 at 0:53
source share

A simple solution that works for me, for working with console ability (ReadKey, etc.), As well as for viewing and saving results:

I am writing a TextWriter that writes to Console and Trace and replaces Console.Out it.

if you use Dialog -> Debugging -> checkmark "Redirect all text of the output window to the immediate window", you will get it in an immediate and fairly clean.

my code: at the beginning of my code:

  Console.SetOut(new TextHelper()); 

and class:

 public class TextHelper : TextWriter { TextWriter console; public TextHelper() { console = Console.Out; } public override Encoding Encoding { get { return this.console.Encoding; } } public override void WriteLine(string format, params object[] arg) { string s = string.Format(format, arg); WriteLine(s); } public override void Write(object value) { console.Write(value); System.Diagnostics.Trace.Write(value); } public override void WriteLine(object value) { Write(value); Write("\n"); } public override void WriteLine(string value) { console.WriteLine(value); System.Diagnostics.Trace.WriteLine(value); } } 

Note: I redefine only what I need, so if you write other types, you should override more

0
Dec 13 '18 at 8:32
source share

Step 1: Right-click on the project name in Solution Explorer, and then make the output type as a window application

Step 2: Debug -> Options ..--> Debug (expand) → General -> Redirect all the text of the output window to the immediate window

-one
Mar 15 '18 at 16:07
source share

You only need to change the type of output in the project settings to the Windows application . Nothing more. Then it will use the Output window instead of the console window.

-one
Sep 13 '18 at 6:43
source share



All Articles