________________________________
From: Sundar Shan <lists@ruby-forum.com>
To: ruby-talk@ruby-lang.org
Sent: Wednesday, February 12, 2014 10:45 AM
Subject: reading input from text file
i want my ruby program to accept input from text file as parameter at
command prompt and produce the and save it another text.
i have all my input for my program at inputfile.txt.
i want my ruby program to accept input from text file as parameter at
command prompt and produce the and save it another text.
i have all my input for my program at inputfile.txt.
You can use the ARGF object to read input from files.
i want my program to work if run prorgram like
ruby filename.rb inputfile.txt > outputfile.txt
For the output, if the above is what you want, you just need to print
to stdout (puts, print, etc), cause you are redirecting to the file at
the shell (> outputfile.txt)
For example:
file_contents = ARGF.read
# do something with file_contents
puts file_contents