views:

2675

answers:

5

Under VS's external tools settings there is a "Use Output Window" check box that captures the tools command line output and dumps it to a VS tab.

The question is: can I get the same processing for my program when I hit F5?

Edit: FWIW I'm in C# but if that makes a difference to your answer then it's unlikely that your answer is what I'm looking for.

What I want would take the output stream of the program and transfer it to the output tab in VS using the same devices that output redirection ('|' and '>') uses in the cmd prompt.

A: 

System.Diagnostics.Debug.Writeline() or Trace.Writeline()

ScaleOvenStove
I'm looking for somethings that works without modify the code that is doing the output.
BCS
A: 

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.

cori
That link isn't it either. Crumbs.
BCS
+1  A: 

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

  1. call printf and print the string
  2. 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 buf[2048];

    // 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. :-)

Mark
C# sorry, but otherwise a good idea.
BCS
paragraph 2 seems to cover this
BCS
+2  A: 

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:

  1. Create a C++ project
  2. Open the project settings, debugging tab
  3. Enable managed debugging
  4. Edit command line to add "> output.txt"
  5. 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.

Jay Bazuzi
+1  A: 

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:

  1. Run cmd.exe
  2. ALT-SPACE, D
  3. In Options, enable QuickEdit mode.
  4. In Layout, set Buffer Height to 9999
  5. Click OK
  6. Exit the CMD window.
Jay Bazuzi
+1 for the configuration of console window. I would add setting Height of Window Size to 50.
AMissico