Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

'gets' flagged as 'Bad file descriptor' - why?

21 views
Skip to first unread message

RLMuller

unread,
May 14, 2003, 1:20:11 PM5/14/03
to
Hi All.

I'm a newbie to Ruby. When I tried running the following code excerpted
from The Ruby Way, p. 405, on a Win2000SP3 system using ruby 1.6.8
(2002-12-24) [i586-mswin32]:

require "win32ole"
print "Enter the filename to print: "
docfile = gets
...

returns an error for line 3:

`gets': Bad file descriptor (Errno::EBADF)

Thanks for any info you may be able to offer.

Regards,
Richard Muller


Hal E. Fulton

unread,
May 14, 2003, 2:15:59 PM5/14/03
to

Hmm. Not sure on this one.

My first question is: Are you running this
by double-clicking on an icon, or from the
command line?


Hal


RLMuller

unread,
May 14, 2003, 2:56:48 PM5/14/03
to
Hi Hal,

Great book!

I've been running from an SciTE environment, where I've run many other Ruby
test pgms. Since you raised the question, I tested from a Command Window
.. successfully! Thanks.

Of course, now I have a Ruby/SciTE question. If you have any suggestion as
whom to contact about that,
I'd appreciate additional advice. Perhaps I'll re-post this question under
a new subject.

Regards,
Richard

Hal E. Fulton

unread,
May 14, 2003, 3:06:43 PM5/14/03
to
----- Original Message -----
From: "RLMuller" <RLMu...@comcast.net>
To: "ruby-talk ML" <ruby...@ruby-lang.org>
Sent: Wednesday, May 14, 2003 1:56 PM
Subject: Re: 'gets' flagged as 'Bad file descriptor' - why?


> Great book!

Thanks...

> I've been running from an SciTE environment, where I've run many other
Ruby
> test pgms. Since you raised the question, I tested from a Command Window

> ... successfully! Thanks.


>
> Of course, now I have a Ruby/SciTE question. If you have any suggestion
as
> whom to contact about that,
> I'd appreciate additional advice. Perhaps I'll re-post this question
under
> a new subject.

Well, I guess what's happening is that when you do a
gets() in that way, without a window, it doesn't know
where/how to get the input.

Maybe a simple GUI would help that. It should only
take a few lines in the GUI of your choice to
throw up a dialog box... of course, to get a little
fancier, you could use some specialized widget that
browses for filenames in a tree.

If you do something like that, why don't you share
it with the list?


Cheers,
Hal

RLMuller

unread,
May 14, 2003, 3:33:23 PM5/14/03
to
Hi Hal,

IMHO, your analysis is right on target. SciTE redirects stdout (and stderr)
to a panel within it's window. But, clearly, they didn't redirect stdin
from that panel (after writing a prompt). So the correct solution, it seem
to me, is an enhancement of that IDE, which I can't afford to volunteer to
try.

So a work-around, as you suggest, is the path of least trouble. The Windows
API has a function for opening an input dialog that accepts a string which
gets returned to the caller. And Win32API provides a way to get to such a
function. That leads me to think that it shouldn't be too difficult to
'def' a static 'wgets' method to return a string from an input dialog.

I'll look into this briefly. If you have any off-hand comments, I'd
appreciate them. If I can't get this going this afternoon, I'll shelve it
in favor of using FX.

C'ya,

daz

unread,
May 16, 2003, 9:38:10 PM5/16/03
to

"RLMuller" <RLMu...@comcast.net> wrote
>
<snip>

>
> The Windows API has a function for opening an input
> dialog that accepts a string which gets returned to
> the caller. And Win32API provides a way to get to such a
> function.
>
>
> From: "Hal E. Fulton" <hal...@hypermetrics.com>
>
<snip>

> >
> > Maybe a simple GUI would help that. It should only
> > take a few lines in the GUI of your choice to
> > throw up a dialog box... of course, to get a little
> > fancier, you could use some specialized widget that
> > browses for filenames in a tree.
> >
> > If you do something like that, why don't you share
> > it with the list?
> >

Swin gives easy access to some Win32 dialogs (and more)
and is included in /\ndy's PragProg distro.
(Part of VisualuRuby on RAA)
English documention is 'swin.c' ;-)


###---<code>

require 'swin'

# OFN_ from 'commdlg.h'
OFN_HIDEREADONLY = 0x0004
OFN_PATHMUSTEXIST = 0x0800
OFN_FILEMUSTEXIST = 0x1000

# Starting directory (uses current 'default', otherwise)
# Dir.chdir('D:\ruby')

# make your own array of file filters
filter = [ ["Text files","*.txt"], ["All files","*.*"] ]

#filename = 'readme.txt' # bypass OpenDialog

filename ||= SWin::CommonDialog::openFilename(nil, filter,
OFN_HIDEREADONLY | OFN_PATHMUSTEXIST | OFN_FILEMUSTEXIST,
'Select File', # Box Title
'txt') # default extension

if !filename
puts 'Open cancelled'
# exit(1)
end

puts filename

#filename = SWin::CommonDialog::saveFilename(nil, filter)
#puts filename

###---</code>

It saves much cutting/pasting/typing of filenames to put this
in simple non-GUI scripts instead of using a filename argument.


daz


0 new messages