Author Topic: How to direct command line output to a file  (Read 1321 times)

0 Members and 1 Guest are viewing this topic.

Offline alias120

  • Subscriber
  • Jr. Member
  • *
  • Posts: 103
  • while(!(succeed = try()));
  • Field: IT Support
  • Real Name: Matthew Balthrop
  • Favorite OS: Windows
  • Programming Language: C++
How to direct command line output to a file
« on: August 17, 2011, 08:42:09 AM »
Have you ever wished that you could save the output from the command line to a file for further examination? Well, here is how you do it! I am going to be using Windows 7 for my example.

-First, click on the start menu.

-Then, open up a new terminal window (search for it by typing cmd.exe in a directory search bar).

-Alright, so we will use ipconfig for our example (displays your computers network config)

-Navigate to whatever directory you would like the text file to appear in.
 
-Type in the following command:
Code: [Select]
ipconfig/all > Test.txt
-Press Enter.

-Notice the ">" character after the ipconfig switch. What that character is essentially
doing is directing the output that would normally appear in the terminal to whatever
destination you specify after the character.
 
-I chose a test file called Test.txt as the target of my output.

-Navigate to whatever directory you saved the file in, and open up the file.

-Voila! Terminal output has been directed to the specified text file!
Code^3
--------
"I do not care if you think slowly, but I wish you would think before you publish."
-Wolfgang Pauli

Offline gbertoli3

  • Expert
  • Sr. Member
  • *
  • Posts: 1,169
  • My Code Is In The Cube
    • Bertoli Family
  • Field: Software & Web Development
  • Real Name: Guido Bertoli
  • Favorite OS: Windows
  • Programming Language: C#
Re: How to direct command line output to a file
« Reply #1 on: August 17, 2011, 11:18:26 PM »
Wow, I had no idea. I'm definitely going to try this out. Do you know what the default directory is for saving files?

Offline alias120

  • Subscriber
  • Jr. Member
  • *
  • Posts: 103
  • while(!(succeed = try()));
  • Field: IT Support
  • Real Name: Matthew Balthrop
  • Favorite OS: Windows
  • Programming Language: C++
Re: How to direct command line output to a file
« Reply #2 on: August 18, 2011, 05:25:17 AM »
Under Windows 7 it will default you into your Users folder. So you would see something like this:

 C:\Users\Matthew>

Except with you name of course. I forgot what it was under Windows XP
Code^3
--------
"I do not care if you think slowly, but I wish you would think before you publish."
-Wolfgang Pauli

Offline no2pencil

  • Contributor
  • Jr. Member
  • *
  • Posts: 64
  • Self improvement is masturbation
    • Akron Computer Design & Repair
  • Field: Software Development
  • Real Name: #2pencil
  • Favorite OS: Linux
  • Programming Language: C
Re: How to direct command line output to a file
« Reply #3 on: November 02, 2011, 12:11:24 PM »
The default directory is going to be whatever directory you are launching the command from. Unless you supply the full path is will be the current directory.