How to output console or PowerShell transcript to a file in Windows

Console output copypaste

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.

Problem

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

OR

executable.exe *>&1 > output.txt

This method just writes everything from the console window to a file, as simple as that!

In these examples:

ElementDescription
Redirection operator: >Writes the command output to a file or a device, such as a printer, instead of the Command Prompt window.
2>&1So 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 🙂

Further reading

For more info and options, see this Stack Overflow thread.

The following two tabs change content below.
Antti Koskela is a proud digital native nomadic millenial full stack developer (is that enough funny buzzwords? That's definitely enough funny buzzwords!), who works as a Solutions Architect for Valo Intranet, the product that will make you fall in love with your intranet. Working with the global partner network, he's responsible for the success of Valo deployments happening all around the world. He's been a developer from 2004 (starting with PHP and Java), and he's been bending and twisting SharePoint into different shapes since MOSS. Nowadays he's not only working on SharePoint, but also on .NET projects, Azure, Office 365 and a lot of other stuff.This is his personal professional (professional, but definitely personal) blog.

2 thoughts on “How to output console or PowerShell transcript to a file in Windows

  1. Actually, in PowerShell, one can indeed merely copypaste the output of a command in a console window. You can pipe in to clip or Set-Clipboard.

    e.g.

    Get-ChildItem | Set-Clipboard

    You can also do it from cmd console by piping into clip.

    dir | clip

    • Hi Joel,

      Thanks for your comment!

      I did focus on redirecting the output to a file in this blog post… But that’s actually a great point – I’ve always just copypasted from the output window, but it IS pretty cumbersome (and unreliable), so your way certainly beats it.

Leave a Reply

Your email address will not be published. Required fields are marked *