« December 2005 | Main

January 07, 2006

Output Redirection from the Windows Command Line

This tip will show you how to write the output of a command at the Windows command line to a file. It's not hard (infact it's one of the very basics of command line programming).

Start Command Line within Windows by choosing Start->Run then entering 'cmd' and pressing enter.

Suppose you want to capture the output from a directory listing, say c:\blah. To get the directory listing to display on the screen you would type the command dir c:\blah which may generate the output:

C:\>dir c:\blah

 Volume in drive C is Windows
 Volume Serial Number is XXXX-YYYY

 Directory of c:\blah

07/01/2006  21:08    <DIR>          .
07/01/2006  21:08    <DIR>          ..
07/01/2006  21:07    <DIR>          folder1
07/01/2006  21:07    <DIR>          folder2
06/03/2005  11:58         5,442,634 music.mp3
07/01/2006  21:07                17 text1.txt
               2 File(s)      5,442,651 bytes
               4 Dir(s)  12,453,460,480 bytes free

 

If you want to capture this listing to the file c:\folder.txt then you would append > c:\folder.txt to the original command, ie:

C:\>dir c:\blah > c:\folder.txt

Notice now that nothing appears on the command line window after this and it simply moves on to the next prompt. If we now check the file c:\folder.txt then we see that it has the contents of the directory.

A slight variant of this is to use the greater than symbol, >, twice, ie:

C:\>dir c:\blah >> c:\folder.txt

This will append the output of the dir command to what is already contained in the file c:\folder.txt.

How to stop .avi files from locking up in Windows Explorer

If you've downloaded a corrupt .avi file in Windows then you may have noticed that if you try to delete, rename or move it that explorer complains that the file is in use. This is because Windows is trying to load the whole file to generate a preview image for you. You can turn this preview off by doing the following:

1) Open the 'Run' dialog box from the start menu (Start->Run or press the Windows and r keys together):
2) To remove image preview, type and hit enter
regsvr32 /u shimgvw.dll
3) To readd image preview, type and hit enter
regsvr32 shimgvw.dll
4) To remove media preview, type and hit enter
regsvr32 /u shmedia.dll
5) To readd media preview, type and hit enter
regsvr32 shmedia.dll

Note: I found this information copy+pasted on a forum so I don't know the original source. 

Adlinks

Creative Commons License
This weblog is licensed under a Creative Commons License.
Powered by
Movable Type 3.2