S
Sea&Gull
Hi!
I have a script.rb which reads some data from stdin.
Something like this:
bash$ cat file_name | script.rb
In script.rb I have:
#--------------------
fi = $stdin
fi.each_line do |l|
#...
end
--------------------
After that script.rb needs to communicate with a user interactively:
ask what to do and read the answer from... stdin. Something like:
#-------------------
print "\nYes/No: "
answer = $stdin.gets
#-------------------
Here I had a problem - I can't read user's answer.
I guess I need somehow to reopen stdin before calling
$stdin.gets but have not found how to do it correctly.
Could you please give me a hint?
Thanks a lot!
I have a script.rb which reads some data from stdin.
Something like this:
bash$ cat file_name | script.rb
In script.rb I have:
#--------------------
fi = $stdin
fi.each_line do |l|
#...
end
--------------------
After that script.rb needs to communicate with a user interactively:
ask what to do and read the answer from... stdin. Something like:
#-------------------
print "\nYes/No: "
answer = $stdin.gets
#-------------------
Here I had a problem - I can't read user's answer.
I guess I need somehow to reopen stdin before calling
$stdin.gets but have not found how to do it correctly.
Could you please give me a hint?
Thanks a lot!