Get a 3 licensed copy of Windows 7 Home Premium at a big discount

You better hurry.... before Microsoft comes to their senses

Are your dual monitors taking up too much space on your desk? If so, get your space back with an adjustable dual monitor mounting stand and declutter your desk with out throwing anything out!

How I added more disk space with out any hassles or costing me an arm and a leg!

Check it out: Quickly Solve Low Disk Space Problems

How To Redirect Output from Windows Command Prompt To A Text File

17

winlogo.jpgNormally, when working with Windows command prompt, output (or returned results) from commands that are executed can be viewed in the command prompt window. For some commands, the output can be several rows long, in which you can use your mouse to scroll up and down to view all the rows.

But say you want to save a copy of the output from the command that was executed. For example when using ipconfig to view the TCP configuration of your computer network card (NIC) or executing the dir command to view a list of directories.

One way is to copy from the command prompt window and paste it in a text file. Unfortunately, this can be cumbersome at times.

Instead, there is a better way to easily capture the output directly from the command prompt window to a file by using the redirection command.

To use the redirect command, just use the symbol > (press Shift + greater than arrow) and the file name at the end of the command you want to execute.

command-redirect1

For example to redirect output of the ipconfig command to the file tcpinfo.txt, enter the following command at the prompt:

ipconfig /all > tcpinfo.txt

This will create the file called tcpinfo.txt in the current directory you are at (shown in below screen shot), with the output results of ipconfig command.

command-redirect2

If you want the file created at another location on your hard drive, enter the full path to that location:

ipconfig /all >c:\mystuff\tcpinfo.txt

When using a single redirect command, it will always over-write (delete) the contents of the file (unless you specify a different file name) before writing any new data.

If you want to append (concatenate) data to an existing file, use two redirection symbols as shown in the following example:

dir c:\mymusic >> c:\tcpinfo.txt

This example adds the output of the dir (directory) command to the end of the file – tcpinfo.txt.

Now, you are not limited to redirecting output to a file. You can also redirect to devices such as a printer.

Say you have a printer connected to LPT1. You would use the following command:

dir c:\mymusic >LPT1

You can also use PRN or CON to output data results. Just make sure the device is working correctly.

Filed under Windows Tips by  #

Comments on How To Redirect Output from Windows Command Prompt To A Text File Leave a Comment

August 4, 2009

Gaurav Bedi @ 3:17 pm #

Hi All,

I am working on CA UNICENTER.
There is one command "pingagt " I am not able to get its output in text file.

PLEASE HELP ME IN THIS.

Regards
Gaurav Bedi

September 13, 2010

john @ 1:50 am #

Use:

C:\> pingagt 2> C:\your_folder\your_text_file.txt

Good times

October 27, 2010

buluq @ 10:36 am #

f:\movies>dir /s > c:\movies.txt

voila! that's i'm talking about.
thanks dude!

November 22, 2010

Dinesh Talla @ 7:20 am #

Hello,

One of my command is opening another cmd prompt and it is writing output to their and not giving time to copy the output.. Is there a work around in this case..

Dinesh

December 4, 2010

Thanks very much,
I searched a lot for this.

December 18, 2010

Ben @ 1:20 pm #

I tried the redirect, and it happens on the screen very quickly, but does not write to a file.

What am I doing wrong?

Ben

Ben @ 6:09 pm #

Hi,
This is the command I used. After it ran I seached the c: drive and could not find the file

ipconfig /all > tcpinfo.txt

Ben

December 19, 2010
April 3, 2011

suda @ 4:52 am #

Wow,..Thanks a lot..!! It really helped me! :)

April 11, 2011

Kulbhushan Mayer @ 4:31 am #

Hi,

I want to redirect the output of one of my command in .bat file to some other file but I am not able to do this.

command I am using is

im copyissue –copyfields –nolink –type="Load Request – PreProduction" –field="Requested Load Date=%PreprodPlannedStart%" –field="Planned End=%PreprodPlannedEnd%" –field="Comments=IM ticket created by script" –field="Checkpoint Label=%CheckpointName%" –field="State=QA Load Approval" –field="Requestor Name=%RequestorName%" –field="Requestor Phone=%RequestorPhone%" –field="File Replacement(s)=%FilesChangedList%" %PPESPCmd1% %PPESPCmd2% %PreprodIMTemplate% > Preprodim.txt

I am using this as:

call xyz.bat >> test.txt (Above mentioned command is the part of xyx.bat)

Regards,
KMayer

July 3, 2011

Devon @ 4:23 pm #

Searched about 10-20 websites for this. Finally found out getting my text from command prompt dumped into notepad is as easy as adding a greater-than symbol and destination text file.

August 25, 2011

veblen @ 5:19 am #

In the dos box at c:\ I typed :

tree C:\users\mmd

which gave me the tree OK,displayed on the screen.
BUT when I added te command to redirect output to a file :

tree C:\users\mmd >tree.txt

I got "Access is denied"

can anyone help me ?

Veblen

September 26, 2011

Niru @ 7:34 pm #

@Devon:

Thanks a lot

October 14, 2011

Nico @ 7:26 am #

@veblen:

Try this: tree C:\users\mmd >%userprofile%\Documents\tree.txt

November 4, 2011

jmb49 @ 7:18 pm #

@veblen :

> BUT when I added te command to redirect output to a file :
> tree C:\users\mmd >tree.txt

Try tree C:\users\mmd > c:\tree.txt instead. I think it creats tree.txt in mmd. But it also locks mmd to tree inside. Well, this may be a locking issue. Tel us please !

November 9, 2011

veblen @ 6:40 am #

Unfortunately above suggestions do not work for meThanks for suggestions.

Leave a Comment

Fields marked by an asterisk (*) are required.

Subscribe without commenting