Output window to file (Visual Studio 2005) - visual-studio

In Visual Studio 2005, how can I save what's written to the output window to a file (I can't change the code writing to the output window, and it writes a lot; I just want to save the output window content to a file)?

"File" -> "SaveOutputAs..." let's you save the contents of the output window to a file, but I imagine you want to redirect the output to a file while debugging? I'm still looking for a way to do that myself..

You can just redirect the output stream in the command line arguments in Visual Studio.
Right click on your project → Properties → Configuration properties → Debugging → Command arguments.
After your arguments, just add:
> outputfile.txt

If you mean the output to the debug/trace window, you can capture this at runtime with DebugView without running Visual Studio.

I just answered a very similar question here. I'm using this method myself to capture, filter and log debug output to a file on Windows Vista 32 bit. I use Visual Studio 2005 and work in C++, so this might help you too.

ATLTrace Tool intercepts the ATLTRACE calls. You can save the output of any process into a file.

Are you developing in .NET? And what is the code used to write to the output window?
In case you are using Trace.WriteLine or Debug.WriteLine you could use a TextWriterFileListener class to write all messages to a file automatically.

If the app runs in a command window, you can use the old DOS redirect command ">" to redirect the output to a file.
For example.
c:\>dir > out.txt
...will redirect the output of the dir command to a file called out.txt. You should be able to do the same with your application.
This will stop the output from going to the console, but you can always go the log file to get you the info you want.

Related

Redirect windows console output from another process to file

I have a DLL which does as plugin into the TS3 client.
The problem is, the plugin provokes a crash that I cannot seem to find in my code directly.
So my idea is to set the Console Output of the console windows in the background (-console option) to a file, because when the program crashes there is no way I can read the console output as the console disappears immediately.
Is there a way to set the output of a crashing console to a file?
Because so far, when using the stdout operator (ts3client_win64 -console > output.txt) it does not write anything to the file. (I assume it cannot close the file handle and loses all its data?) But I want to keep the console output when the crash occurs.
It also has to be said that I can not just run it with a batch file and a pause statement, because when starting the application it opens its own console window (and thats the one of which I want the output).
It is the type of crash one would get from failed (safe) string operations in C like strtok_s or strcpy_s.

Windows NTSD Debugger

I am doing some debugging of a crash dump file using NTSD. Is it possible to redirect all the output that I am seeing on console now to a txt file? I am getting all the call stacks of all the threads however can't see that information in a debugger window.
Thanks
Look at the .logopen and .logclose commands. You should be able to do .logopen foo.txt, issue your command (which I'm assuming is ~*k), and then when it's done, do .logclose.

Hold command prompt window in Visual Studio, when using Command Line Arguments

I need to test my console application with example input data, stored in a file. I want this file to be executed when I start my application in Visual Studio. In normal situation, in command prompt I write: program.exe < input.txt , the program is executed, I get the results and the screen (prompt) waits. I have found in Visual Studio that I can write this: "< input.txt" in Project->Properties->Debug->Command Line Arguments and when I hit F5 I can see that the program gives me the results, but the command window closes immediately. How can I hold this Window? I tried Ctrl+F5, but it doesn't load my input.txt file. Also the application is going to be send to another test system, so I should not write any Console.Read() (ReadLine, Readkey...) methods in the end of the file, because I think this will mess things up. I need answers for this problem for Visual Studio 2010 (2008, 2005) and languages: C/C++, C# if possible.
Just a quick hack if you can't work it out
if (System.Diagnostics.Debugger.IsAttached)
{
Console.WriteLine("Press [ENTER] to finish");
Console.Read();
}

How to make output visible while running the code from VS?

I can see the output window with logging information only when I stop/exit the application. How to make it visible while running the code from VS?
Open Output window before or while running the application (View -> Output or ALT+2).

Output a watched Visual Studio variable to a file

Is there a way in Visual Studio (2008 if it matters) that I can, in debug/break mode, write the contents of a variable to a text/XML file?
The scenario is that I have a long process running in debug and I have realised too late that I haven't logged enough detail about the events that the process has been monitoring, but fortunately a history is still available within a variable in the code.
I could trawl through the tens of thousands of items in this list, but it's not going to persist once I hit stop on the application ... there is no obvious context option for this, but is there any way, a better way than manual? Or is there no hope and I just need to hit stop, re-tool the logging function and run the thing again?
Aside from trying to hit a breakpoint, modify the code and re-write to make a better logger, is there a way of not losing that in-memory data?
One way to do it would be to use the immediate window (menu Debug -> Windows -> Immediate). In the window that appears you can use the "?" to query the value of a variable.
Assuming your history variable is a string you view its contents by typing the following in the immediate window:
?history
You could copy and paste the output from there into a text file or alternatively ask Visual Studio to log all command window output. To do this type:
>log "c:\test.log"
>? history
>log off
Log is an alias for Tools.LogCommandWindowOutput and accepts the following parameters:
Tools.LogCommandWindowOutput [filename] [/on|/off] [/overwrite]
Check out the MSDN article Log Command Window Output Command for more information.
 
I think that my answer is pretty much the same as JamesPickrell's, but from the Immediate Window you could also do something like this:
My.Computer.FileSystem.WriteAllText("c:\temp.txt",history,True)
This would output the content of the "history" variable to a file called c:\temp.txt.
Thanks to Richard's answer, this is working for me.
System.IO.File.WriteAllBytes(#"c:\Temp\temp.txt", myVar);
Make sure that C:\Temp exists.
The reason for writing to a folder and not to the root C:\ is to avoid UnauthorizedAccessException when not running Visual Studio as administrator.
I found useful/demonstrative/shareable to save the variable as a json string to the file. From Immediate Window enter the following:
string jsonedVariable = Newtonsoft.Json.JsonConvert.SerializeObject(VARIABLE);
System.IO.File.WriteAllText(#"C:\FILENAME.json", jsonedVariable);
Not sure from which version it's supported, but you can simply put it in the WATCH window, then right-click copy past wherever you want.

Resources