Reputation: 35
I wrote a code in ruby which basically takes 3 commandline args followed by userinput from the keyboard. The problem is when i am executing the code without command line, it is able to read userinput but with command line it is throwing error `gets': No such file or directory - 3024 (Errno::ENOENT) Dont understand why
class Matching
attr_reader :sys_count
def initialize()
@sys_count = gets
throw "Bad count" unless @sys_count.to_i > 0
end
def get_match
count = @sys_count
return nil unless count
ret = count
count.to_i.times do
ret += gets
end
((count.to_i * (count.to_i - 1))/2).times do
while true do
line = gets
ret += line
break if line == "\n"
end
end
ret
end
def packet
str = get_match
return nil unless str
"matched 0\njava\n" + str
end
end
CONN=ARGV[0]
CONFIG=ARGV[1]
OUT_BASE=ARGV[2]
obj=Matching.new()
out=obj.packet
print out
Is there any workaround to make it work ~
Upvotes: 0
Views: 57
Reputation: 59232
You need to specifically state that you need the input from the input device, as opposed to command line arguments ARGV
, and since gets
is generic, you've to be specific in this case to avoid confusions or misinterpretation.
So, replace all gets
with $stdin.gets
or STDIN.gets
, which gets the input from the standard input.
Upvotes: 1