optparse and gets

B

Bauduin Raphael

Hi,

I'm using optparse.
At a certain point in the program, I need a confirmation (exept if
--no-confirm is used as argument).

Here's a program illustrating my question:

#!/usr/bin/env ruby

require 'optparse'

opts = OptionParser.new
opts.on("--no-confirm" ) { |val| confirm=false }

puts "enter string:"
s = gets
puts "you entered #{s}"


when calling this script without any argument, it runs fine.
But once I pass it the --no-confirm argument, if fails with this message:

../test.rb:9:in `gets': No such file or directory - --no-confirm
(Errno::ENOENT)
from ./test.rb:9

I have fixed the problem by calling $stdin.gets instead. But I don't see
what caused the problem in the first place, and I'm curious enough to
send a message here ;-)

thanks for any indication.

Raph
 
N

nobu.nokada

Hi,

At Wed, 29 Dec 2004 05:56:47 +0900,
Bauduin Raphael wrote in [ruby-talk:124673]:
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,982
Messages
2,570,185
Members
46,738
Latest member
JinaMacvit

Latest Threads

Top