I have a Ruby program (school project) where I need to specify a server and port like so:
ruby program.rb -s servername -p 8080
I also need to be able to input a file as STDIN (using the < operator in linux/unix terminal)
ruby program.rb -s servername -p 8080 < testfile.txt
I made a test ruby script that just puts gets
. When running it like this
ruby test.rb -s servername -p 8080 < testfile.txt
I get this error:
test.rb:5:in 'gets': No such file or directory @ rb_sysopen - -s (Errno::ENOENT)
When I play around with the parameters, it looks like Ruby is trying to open a file with the name of the first parameter ("-s" in this case) instead of the file specified after the <
operator.
Any way to fix this? I've gotten the same error on both Ruby 2.1.0 and 2.1.5.
EDIT: Just tried doing STDIN.readline and it works fine... what???