0

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???

the Tin Man
  • 158,662
  • 42
  • 215
  • 303
  • 1
    Code might make it easier to debug. – Dave Newton Nov 24 '14 at 21:47
  • 1
    First, consider whether you want to get answers for your school project, where you are supposed to figure it out yourself, as part of your learning process. Remember, any answers we add are easily found by a teacher/professor. And, as @DaveNewton said, we need to see code if we're going to help you with anything beyond a wild guess. – the Tin Man Nov 24 '14 at 22:13

1 Answers1

0

When you just call gets you are calling Kernel#gets.

When you call STDIN.gets then you are calling IO#gets.

I agree, it is a bit wonky.

ihaztehcodez
  • 2,123
  • 15
  • 29