Output redirection to a file from the Windows Command Line
Published 2 years, 5 months ago in Tips and WindowsThis 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-YYYYDirectory 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.
If you have a website, consider joining the Money4Banners advertising network. They will pay you £10 + £5 each month for displaying a small advert on three of your pages, regardless of traffic. American webmasters are welcome, and since £10 == $20, you make more!
2 Responses to “Output redirection to a file from the Windows Command Line”
Leave a Reply
You must log in to post a comment.
Search
Categories
- ASP (3)
- ASP Basics (3)
- Blogs (2)
- C# (1)
- deals (1)
- Firefox (1)
- Flash (1)
- Google (6)
- Hacks (4)
- Java (1)
- PHP (12)
- Basics (8)
- Files (1)
- Image Handling (3)
- Puzzles (1)
- Ruby (1)
- Tips (10)
- Web Hosting (3)
- Web Hosting Articles (1)
- Web Hosting News (2)
- Windows (6)
- Wordpress (2)
Related Entries
- List all processes with the Windows Command Line
- Kill a Process from the Windows Command Line
- How To Add A New Line in a C# or Visual Basic TextBox
- Reading a file's contents with PHP
- How to stop .avi files from locking up in Windows Explorer
- The Difference Between require() and include()
- Add Notepad To Your "Send To" Menu
- Rotating Images with PHP
- Temperature Conversion Program in Java
- Write text on a dynamically generated image using PHP
Good one buddy, I was just looking for this small tip and found it here. Thanks.
Same here…thanks for the quick tip. It was useful