On Wed, Feb 12, 2014 at 5:45 PM, Sundar Shan <lists / ruby-forum.com> wrote:
> 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

Now:

$ ruby test_argf.rb test.txt > result.txt
cat result.txt
aaaaa
bbbbb
ccccc

Hope this helps,

Jesus.