Capture console output for debugging in VS?

I'm going to make a few assumptions here. First, I presume that you are talking about printf output from an application (whether it be from a console app or from a windows GUI app). My second assumption is the C language.

I'm going to make a few assumptions here. First, I presume that you are talking about printf output from an application (whether it be from a console app or from a windows GUI app). My second assumption is the C language.To my knowledge, you cannot direct printf output to the output window in dev studio, not directly anyway.

Emphasis added by OP There might be a way but I'm not aware of it. One thing that you could do though would be to direct printf function calls to your own routine which will call printf and print the string call OuputDebugString() to print the string to the output window You could do several things to accomplish this goal. First would be to write your own printf function and then call printf and the OuputDebugString() void my_printf(const char *format, ...) { char buf2048; // get the arg list and format it into a string va_start(arglist, format); vsprintf_s(buf, 2048, format, arglist); va_end(arglist); vprintf_s(buf); // prints to the standard output stream OutputDebugString(buf); // prints to the output window } The code above is mostly untested, but it should get the concepts across.

If you are not doing this in C/C++, then this method won't work for you. :-).

C# sorry, but otherwise a good idea. – BCS Sep 23 '08 at 19:12 paragraph 2 seems to cover this – BCS Jun 18 '09 at 18:06 stackoverflow. Com/questions/587767/… seems to describe how to get it to work, though using OutputDebugString works well, too.

– rogerdpack Mar 13 at 5:02.

You should be able to capture the output in a text file and use that. I don't have a VS handy, so this is from memory: Create a C++ project Open the project settings, debugging tab Enable managed debugging Edit command line to add "> output. Txt" Run your program under the debugger If things work the way I remember, this will redirect STDOUT to a file, even though you're not actually running under CMD.EXE.(The debugger has its own implementation of redirection syntax, which is not 100% the same as cmd, but it's pretty good.) Now, if you open this file in VS, you can still see the output from within VS, although not in exactly the same window you were hoping for.

The console can redirect it's output to any textwriter. If you implement a textwriter that writes to Diagnostics. Debug, you are all set.

Here's a textwriter that writes to the debugger. Using System. Diagnostics; using System.IO; using System.

Text; namespace TestConsole { public class DebugTextWriter : TextWriter { public override Encoding Encoding { get { return Encoding. UTF8; } } //Required public override void Write(char value) { Debug. Write(value); } //Added for efficiency public override void Write(string value) { Debug.

Write(value); } //Added for efficiency public override void WriteLine(string value) { Debug. WriteLine(value); } } } Since it uses Diagnostics. Debug it will adhere to your compiler settings to wether it should write any output or not.

This output can also be seen in Sysinternals DebugView. Here's how you use it: using System; namespace TestConsole { class Program { static void Main(string args) { Console. SetOut(new DebugTextWriter()); Console.

WriteLine("This text goes to the Visual Studio output window. "); } } } If you want to see the output in Sysinternals DebugView when you are compiling in Release mode, you can use a TextWriter that writes to the OutputDebugString API.It could look like this: using System. IO; using System.Runtime.

InteropServices; using System. Text; namespace TestConsole { public class OutputDebugStringTextWriter : TextWriter { DllImport("kernel32. Dll") static extern void OutputDebugString(string lpOutputString); public override Encoding Encoding { get { return Encoding.

UTF8; } } //Required public override void Write(char value) { OutputDebugString(value.ToString()); } //Added for efficiency public override void Write(string value) { OutputDebugString(value); } //Added for efficiency public override void WriteLine(string value) { OutputDebugString(value); } } }.

Very nice. I which I could accept two answers. – BCS Apr 7 at 16:15.

Maybe this will work for you: set a breakpoint on the close } in Main, and then look at the console window before it closes. You can even copy the text out of it if you need to. On every machine that I use for development, I configure my console window in a certain way, which happens to make this approach work better: Run cmd.

Exe ALT-SPACE, D In Options, enable QuickEdit mode. In Layout, set Buffer Height to 9999 Click OK Exit the CMD window.

1 for the configuration of console window. I would add setting Height of Window Size to 50. – AMissico Mar 25 '10 at 18:35.

1 I'm looking for somethings that works without modify the code that is doing the output. – BCS Sep 23 '08 at 19:11.

You can use Systems.Diagnostics. Trace class to write your output to the Output window instead of (or in addition to) the console. It take a little configuration, but it works.Is that along the line of what you want?

You can also add your own tab per this article, but I've never tried it.

That link isn't it either. Crumbs. – BCS Sep 23 '08 at 19:17.

The lack of printf output in the Output window is mystifying. Where does printf output go then, when you're debugging?

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions