1. Technology
You can opt-out at any time. Please refer to our privacy policy for contact information.

Using the Command Line


6 of 10

Use Pipe Characters to Redirect Output

Using the pipe characters is an important skill to master, as these characters will alter the input or output of a Ruby script. In this example, the > character is used to redirect the output of test.rb to a text file called test.txt instead of printing to the screen.

If you open new test.txt file after you run the script, you'll see the output of the test.rb Ruby script. Knowing how to save output to a .txt file can be very useful. It allows you to save program output for careful examination or to be used as input to another script at a later time.

C:\scripts>ruby example.rb >test.txt
  1. About.com
  2. Technology
  3. Ruby
  4. Beginning Ruby
  5. Using the Command Line

©2014 About.com. All rights reserved.