question about I/O and pipes

J

Jean-Baptiste

There is a (very) little programm (count.rb) which count lines:

cnt = 0
$stdin.each_line {|line| cnt = cnt + 1 }
print cnt,"\n"


Now I want to use it whith pipes like this:
dir | count
but i got this error
C:\ruby>dir | count
C:/ruby/count.rb:3:in `each_line': Bad file descriptor (Errno::EBADF)
from Z:/ruby/count.rb:3

What is the problem?
(NB: I an working on Windows2000.)


Thanks
 
R

Robert Klemme

Jean-Baptiste said:
There is a (very) little programm (count.rb) which count lines:

cnt = 0
$stdin.each_line {|line| cnt = cnt + 1 }
print cnt,"\n"


Now I want to use it whith pipes like this:
dir | count
but i got this error
C:\ruby>dir | count
C:/ruby/count.rb:3:in `each_line': Bad file descriptor (Errno::EBADF)
from Z:/ruby/count.rb:3

What is the problem?
(NB: I an working on Windows2000.)

I guess that's the problem. AFAIK there are some troubles with Windows
pipes...

robert
 
N

nobu.nokada

Hi,

At Thu, 18 Dec 2003 19:57:08 +0900,
Jean-Baptiste said:
Now I want to use it whith pipes like this:
dir | count
but i got this error
C:\ruby>dir | count
C:/ruby/count.rb:3:in `each_line': Bad file descriptor (Errno::EBADF)
from Z:/ruby/count.rb:3

What is the problem?
(NB: I an working on Windows2000.)

See [ruby-talk:84112], http://ruby-talk.com/84112
 
T

Trey Campbell

Robert said:
I guess that's the problem. AFAIK there are some troubles with Windows
pipes...

robert
I get the same error for:
c:> dir | count
but it appears to work as you'd expect for:
c:> dir | ruby count.rb

Does that help?

Trey
 
A

Alfio Astanti

Randy W. Sims said:
One more time with a little less perl.

-----><8-----
@rem = '--*-Ruby-*--
@echo off
if "%OS%" == "Windows_NT" goto WinNT
ruby -x -S "%0" %1 %2 %3 %4 %5 %6 %7 %8 %9
goto endofruby
:WinNT
ruby -x -S %0 %*
if NOT "%COMSPEC%" == "%SystemRoot%\system32\cmd.exe" goto endofruby
if %errorlevel% == 9009 echo You do not have Ruby in your PATH.
if errorlevel 1 goto script_failed_so_exit_with_non_zero_val 2>nul
goto endofruby
@rem ';
#!ruby
#line 15

cnt = 0
$stdin.each_line {|line| cnt = cnt + 1 }
print cnt,"\n"

__END__
:endofruby
-----><8-----


How is supposed to work?

With ruby 1.8.0 (2003-08-04) [i386-mswin32] I got:

F:\ruby\>count < count.bat
ruby: No such file or directory -- count (LoadError)

I get the same if I just type count (+ENTER) while double-clicking reads STDIN ...

Confused
AA
 

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,764
Messages
2,569,564
Members
45,039
Latest member
CasimiraVa

Latest Threads

Top