How to capture command line output to file in Windows

This tutorial will teach you how to capture command line output to a text file in Windows and also how to automatically create a list of all files & folders from specific location, instead of type one by one.

Executing ping command in Windows command prompt

This is a quick tutorial on how to capture command line output to file in Windows. This is useful for a variety of reasons, but it really comes in handy when you are trying to fix a problem in your computer, and you need to send data to someone else to help you out.

This is what you normally would do: You would open the Command Prompt and type the command and wait for the output; right-click in the window and select mark, select the content that you need. Create a new text file, paste the output result, and finally save the file. This process is about 7 steps!

Capturing commands output

There is an easier way to do this with a command line switch; it will reduce from 7 steps in to 2.

1. Open Windows Command Prompt or cmd.

2. Type the command you wish like this:

ping google.com >C:\filename.txt

and press Enter. The (>) symbol is what makes all possible, in conjunction with the destination file, to pour whatever is the outcome of the command to a file.

You won’t see the output result in the command prompt window, but you’ll see its content when you open the file. If you need to append results to the contents of an existing text file use the following symbols >>

(ping bing.com>>C:\filename.txt).

Not only you can use txt file extension but you can also use the old Microsoft Office extensions, like doc or xls.

Tip: If you need to create a list of all the files and folders from specific location, instead of type one by one, use this command:

  • C:\”Folderlocation”> dir /b >c:\your_output_file_name.csv

Or if you need to create a list of specific type of file, use this command:

  • C:\”Folderlocation”> dir *.doc/b >C:\ your_output_file_name.csv

(*) represents any name and (.doc) the kind of file that you want a list from and (/b) uses bare format (no heading information or summary).

Using CSV format will generate an excel type file and every entry will be organized in cells.

All these should work in Windows XP, Windows Vista, Windows 7; etc.

That is all there is to it!

About the author

Mauro Huculak is a Windows expert and the Editor-in-Chief who started Pureinfotech in 2010 as an independent online publication. He is also been a Windows Central contributor for nearly a decade. Mauro has over 12 years of experience writing comprehensive guides and creating professional videos about Windows, software, and related technologies, including Android and Linux. Before becoming a technology writer, he was an IT administrator for seven years. In total, Mauro has over 20 years of combined experience in technology. Throughout his career, he achieved different professional certifications from Microsoft (MSCA), Cisco (CCNP), VMware (VCP), and CompTIA (A+ and Network+), and he has been recognized as a Microsoft MVP for many years. You can follow him on X (Twitter), YouTube, LinkedIn and About.me.