Highline giving EOFERROR, input stream exhausted

I am first taking multiline input from user. User may end input using
Ctr-d.

Then I use highline’s menu and get:
/opt/local/lib/ruby1.9/gems/1.9.1/gems/highline-1.5.2/lib/highline.rb:603:in
`get_line’: The input stream is exhausted. (EOFError)

However, experimentally, if I end multiline input on user entering
“bye”, then highline works, but with Ctrl-D it bombs.

How can i clear EOF prior to calling highline. I tried:

HighLine.track_eof = false

but it pushes the error further (split on nil).

I’ve tried reopening stdin with a $stdin.reopen ‘/dev/tty’ but it makes
no difference.

My earlier code is:

def get_lines
lines = nil
#$stdin.flush
$stdin.each_line do |line|
line.chomp!
if line =~ /^bye$/
break
end
if lines
lines << “\n” + line
else
lines = line
end
end
return lines
end

After calling get_lines, I call this method:

def _choice prompt, choices
#HighLine.track_eof = false
puts "got: #{prompt} ::: #{choices} "
#$stdin.flush
STDIN.reopen ‘/dev/tty’
choose do |menu|
menu.prompt = prompt
menu.choices(choices) do |n| return n; end
end
end

I copied your program and ran it:

$ ruby high.rb
/opt/local/lib/ruby1.9/1.9.1/pathname.rb:270: warning: `*’ interpreted
as argument prefix
one
two
three
“one\ntwo\nthree”
got: ? ::: A choice

  1. A choice
    ?
    /opt/local/lib/ruby1.9/gems/1.9.1/gems/highline-1.5.2/lib/highline.rb:603:in
    get_line': The input stream is exhausted. (EOFError) from /opt/local/lib/ruby1.9/gems/1.9.1/gems/highline-1.5.2/lib/highline.rb:624:inget_response’
    from
    /opt/local/lib/ruby1.9/gems/1.9.1/gems/highline-1.5.2/lib/highline.rb:218:in
    ask' from /opt/local/lib/ruby1.9/gems/1.9.1/gems/highline-1.5.2/lib/highline.rb:317:inchoose’
    from high.rb:25:in _choice' from high.rb:32:in

ruby 1.9.1p376 (2009-12-07 revision 26041) [i386-darwin10]

MAC OSX Intel Snow Leopard
Darwin laptop-3.local 10.3.0 Darwin Kernel Version 10.3.0: Fri Feb 26
11:58:09 PST 2010; root:xnu-1504.3.12~1/RELEASE_I386 i386

Thanks.

On Jun 25, 2010, at 5:36 AM, R… Kumar wrote:

I am first taking multiline input from user. User may end input using
Ctr-d.

Then I use highline’s menu and get:
/opt/local/lib/ruby1.9/gems/1.9.1/gems/highline-1.5.2/lib/highline.rb:603:in
`get_line’: The input stream is exhausted. (EOFError)

Interesting. Your code does work for me:

$ cat multi-read.rb
#!/usr/bin/env ruby -wKU

require “rubygems”
require “highline/import”

def get_lines
lines = nil
$stdin.each_line do |line|
line.chomp!
if line =~ /^bye$/
break
end
if lines
lines << “\n” + line
else
lines = line
end
end
return lines
end

def _choice prompt, choices
puts "got: #{prompt} ::: #{choices} "
STDIN.reopen ‘/dev/tty’
choose do |menu|
menu.prompt = prompt
menu.choices(choices) do |n| return n; end
end
end

p get_lines
_choice "? ", “A choice”

END
$ ruby multi-read.rb
one
two
three
“one\ntwo\nthree”
got: ? ::: A choice

  1. A choice
    ? 1
    “A choice”

I used Control-D to stop the multi-line entry there.

What platform are you on and what version of Ruby are you using?

James Edward G. II

James Edward G. II wrote:

On Jun 26, 2010, at 5:36 AM, R… Kumar wrote:

/opt/local/lib/ruby1.9/�

It looks like this is a difference in Ruby 1.9 that isn’t related to
HighLine:

$ cat eof_change.rb
puts “Enter multiple lines:”
p $stdin.read

puts “Question?”
p $stdin.gets

Yup.
I ran your snippet with 1.9.1 and with the stock /usr/bin/ruby (ruby
1.8.7 (2009-06-08 patchlevel 173) [universal-darwin10.0]) which I never
use, and I get the same results. 1.9.1 fails, 1.8.7 works :frowning:

Do you know who to forward this issue to ? Could you possibly inform the
correct person – I am not familiar with the process.

I have an unrelated question. Some months ago i checked the RVM site and
was frightened off – it said DO NOT install rvm using gem, and it gave
some complicated procedure.
Did you install the rvm gem ? If not, is there a link for the best
procedure to install. I am now a bit weary of custom installs, it take
too much out of me to keep maintaining them. Thanks.

On Jun 26, 2010, at 5:36 AM, R… Kumar wrote:

/opt/local/lib/ruby1.9/…

It looks like this is a difference in Ruby 1.9 that isn’t related to
HighLine:

$ cat eof_change.rb
puts “Enter multiple lines:”
p $stdin.read

puts “Question?”
p $stdin.gets

END
$ ruby -v eof_change.rb
ruby 1.8.6 (2010-02-05 patchlevel 399) [i686-darwin10.2.0]
Enter multiple lines:
one
two
three
“one\ntwo\nthree\n”
Question?
answer
“answer\n”
$ rvm use 1.9.2

info: Using ruby 1.9.2 preview3
$ ruby -v eof_change.rb
ruby 1.9.2dev (2010-05-31 revision 28117) [x86_64-darwin10.3.0]
Enter multiple lines:
one
two
three
“one\ntwo\nthree\n”
Question?
nil

I can’t seem to find a way around it.

James Edward G. II

On Jun 26, 2010, at 1:22 PM, R… Kumar wrote:

Do you know who to forward this issue to ? Could you possibly inform the
correct person – I am not familiar with the process.

I’ve asked if this is an intentional change on the Ruby Core mailing
list.

I have an unrelated question. Some months ago i checked the RVM site and
was frightened off – it said DO NOT install rvm using gem, and it gave
some complicated procedure.
Did you install the rvm gem ? If not, is there a link for the best
procedure to install. I am now a bit weary of custom installs, it take
too much out of me to keep maintaining them. Thanks.

RVM has instructions for how to install it an it is capable of
maintaining itself:

http://rvm.beginrescueend.com/rvm/install/

It’s pretty painless and I highly recommend it.

James Edward G. II