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.
well, here you setup stdin of the script.rb to be a pipe and therefore it has
no controlling terminal:
bash$ cat file_name | script.rb
so, even if you reopen it it will still be a pipe - you cannot get back at the
terminal. i think what you are saying is that you want to open the console
after reading stdin. so maybe:
harp:~ > printf "42\n" | ruby a.rb
42
then i type 42 followed by ctrl-d
hth.
-a
···
On Tue, 13 Sep 2005, Sea&Gull wrote:
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?
--
email :: ara [dot] t [dot] howard [at] noaa [dot] gov
phone :: 303.497.6469
Your life dwells amoung the causes of death
Like a lamp standing in a strong breeze. --Nagarjuna
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?
well, here you setup stdin of the script.rb to be a pipe and therefore it has
no controlling terminal:
bash$ cat file_name | script.rb
so, even if you reopen it it will still be a pipe - you cannot get back at the
terminal. i think what you are saying is that you want to open the console
after reading stdin. so maybe: