Every now and then, you run into a situation, where you’ll need to somehow output the transcript of a console app run. I’m actually going to argue it happens a lot more often than one would think – in my case, any time a customer requires a webjob or a function, that one would normally deploy to Azure, being ran on the servers of the customer.
Something breaks or the app crashes, and the error is logged to event log… But just the error, not the whole transcript. You’d like to get it all, to figure out what’s actually going on, but event log is not the way to go.
What to do?
Solution: redirect the output directly to a file
It’s luckily pretty easy. There are multiple ways to pipe, dump, mirror or just save the output, but since I hate always googling for them (and for the life of me, I can’t seem to remember it by heart), I’m documenting my preferred way here.
You can direct the whole console transcript to a text file by doing something like this:
executable.exe > output.txt 2>&1
executable.exe *>&1 > output.txt
This method just writes everything from the console window to a file, as simple as that!
In these examples:
|Redirection operator: >||Writes the command output to a file or a device, such as a printer, instead of the Command Prompt window.|
|2>&1||So this command first redirects stdout to the output file, and then redirects stderr there as well.|
Okay – now it’s documented. Finally!
Maybe I won’t have to google it the next time 🙂
For more info and options, see this Stack Overflow thread.
Latest posts by Antti K. Koskela (see all)
- Speaking at SPS Twin Cities! - April 9, 2018
- Opening a web part page in maintenance mode - March 27, 2018
- Troubleshooting: Anonymous access on a public SharePoint site collection failing - March 22, 2018