Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I redirect output from the Visual Studio debugger?

In Visual Studio 2008, I can specify a message to be printed when a breakpoint is hit (by right-clicking the breakpoint and choosing 'When Hit...'). When the program is run, these messages appear in the Output Window. I would like to know, is there any way to redirect them to a file?

Specifying >file.txt as a command argument to the program does not work: this redirects the program's output, but not the debugger's.

(FWIW the behaviour I wish to achieve is to get the debugger to repeatedly print a variable's value to a file, rather than peppering my code with printf/cout statements.)

like image 789
jeatsy Avatar asked Apr 06 '10 17:04

jeatsy


People also ask

How do I show Debug output in Visual Studio?

To see the debug output window, in Microsoft Visual Studio, click View, click Other Windows, and then click Output. You can view the debug output in this window only if the debugger is attached to the process that is writing to the output window.

How do I get out of debug mode in Visual Studio?

To end a debugging session in Microsoft Visual Studio, from the Debug menu, choose Stop Debugging.

How do I set Debug path in Visual Studio?

In Solution Explorer, right-click the project and choose Properties. In the side pane, choose Build (or Compile in Visual Basic). In the Configuration list at the top, choose Debug or Release. Select the Advanced button (or the Advanced Compile Options button in Visual Basic).


2 Answers

Under Windows 2000, XP, Server 2003 and Vista DebugView will capture:

  • Win32 OutputDebugString
  • Kernel-mode DbgPrint
  • All kernel-mode variants of DbgPrint implemented in Windows XP and Server 2003

DebugView allows you to filter the output, add time stamps and log to file.

The catch is, you need to run without attaching to the debugger, for DbgView to capture the output. (Use Ctrl+F5)

like image 36
Carl Avatar answered Sep 22 '22 17:09

Carl


  1. Set the option Redirect all Output Window text to the Immediate Window. We find it in ToolsOptionsDebuggingGeneral (fifth to last item).

  2. Open the Immediate Window: Ctrl + Alt + I or DebugWindowsImmediate Window

  3. Enter a command like the following in the Immediate window:

    > Tools.LogCommandWindowOutput /on C:\mylogfile.txt
    
  4. To stop writing to the file, enter the following command in the Immediate window:

    > Tools.LogCommandWindowOutput /off
    
like image 92
Francuz Avatar answered Sep 21 '22 17:09

Francuz