[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

optparse and gets

Bauduin Raphael

12/28/2004 8:56:00 PM

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
1 Answer

nobu.nokada

12/29/2004 12:30:00 AM

0

Hi,

At Wed, 29 Dec 2004 05:56:47 +0900,
Bauduin Raphael wrote in [ruby-talk:124673]:
> #!/usr/bin/env ruby
>
> require 'optparse'
>
> opts = OptionParser.new
> opts.on("--no-confirm" ) { |val| confirm=false }
opts.parse!(ARGV)
> puts "enter string:"
> s = gets
> puts "you entered #{s}"

--
Nobu Nakada