Bad file descriptor, but not on 2/3 computers

I am running a Ruby program that takes files from the command line and
then edits them based on user input. This part works perfectly fine.

The issue I am having is that when I pass an input file I am getting
an error:
“in ‘gets’: Bad file descriptor (Errno::EBADF)”

I have tested this program on three machines, a windows laptop, a mac
laptop, and a windows desktop.

The program runs perfectly on the two laptops, but not on my desktop.

The command line for the file looks like: Decrypt.rb test1.in test2.in
<input.in

I have no idea what that error is dealing with because the program runs
perfectly on the two laptops.

Thank you,
Tag

The issue I am having is that when I pass an input file I am getting
an error:
“in ‘gets’: Bad file descriptor (Errno::EBADF)”

Could try other ruby versions.
-rp

Roger P. wrote:

Could try other ruby versions.
-rp

Thank you Roger, I had forgot to mention that the program is part of a
class and the online grading system only takes the ruby version I am
using. (1.8.7)

All three computers use the same Ruby version.

“in ‘gets’: Bad file descriptor (Errno::EBADF)”

I have no idea what that error is dealing with because the program runs
perfectly on the two laptops.

I have seen something like this before, with 1.9…re-running the script
(perhaps after a few second pause) fixed it there, and I was never able
to come up with a reproducible test script to reproduce the problem. If
you can then forward it on.
-rp

I have seen something like this before, with 1.9…re-running the script
(perhaps after a few second pause) fixed it there, and I was never able
to come up with a reproducible test script to reproduce the problem. If
you can then forward it on.
-rp

To be honest I’m not precisely sure what you mean. This error occurs
every time I run the program.

It takes command-line arguments: Decrypt.rb test1.in test2.in < input.in

The program runs perfectly on the two laptops, but not on my desktop.

The command line for the file looks like: Decrypt.rb test1.in test2.in
<input.in

That is indeed odd. You’d have to go down into the C to see why that is
happening (and try to reproduce it with “straight C” or what not).

Perhaps it is caused by a subtle difference in OS or msvcrt.dll version?

Anyway, you could work around by noting that gets “by default” reads
from the files passed as parameters:

http://stackoverflow.com/questions/2294439/unexpected-gets-behavior-with-commandline-arguments-in-ruby-closed

But I’d probably do something like
$ ruby Decrypt.rb test1.in test2.in input.in

file = File.open(ARGV.pop, ‘r’)
file.gets

GL.
-rp

But I’d probably do something like
$ ruby Decrypt.rb test1.in test2.in input.in

file = File.open(ARGV.pop, ‘r’)
file.gets

GL.
-rp

Thank you. :slight_smile:

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs