Reputation: 1147
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.)
Upvotes: 17
Views: 18866
Reputation: 461
Set the option Redirect all Output Window text to the Immediate Window. We find it in Tools → Options → Debugging → General (fifth to last item).
Open the Immediate Window: Ctrl + Alt + I or Debug → Windows → Immediate Window
Enter a command like the following in the Immediate window:
> Tools.LogCommandWindowOutput /on C:\mylogfile.txt
To stop writing to the file, enter the following command in the Immediate window:
> Tools.LogCommandWindowOutput /off
Upvotes: 27
Reputation: 44438
Under Windows 2000, XP, Server 2003 and Vista DebugView will capture:
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)
Upvotes: 4
Reputation: 36072
I don't know of a way to write the output window contents to a file short of writing a VS plugin, but you can highlight the text in the output window and copy it to the clipboard, then paste it into a text file.
Upvotes: -1