Forum: Ruby Re: Command Line Processing / Pipes

Announcement (2017-05-07): is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see and for other Rails- und Ruby-related community platforms.
Stuart H. (Guest)
on 2006-05-18 19:02
(Received via mailing list)
Hi Chris,

Sorry, I forgot about 'cat' being a non-standard cmd. It's on this
machine as part of Cygwin. The one liner you gave me works great. It can
accept filenames as arguments and STDIN via a pipe. Howerver, what I am
going to be doing is too complex for a one line script so I will need to
put it in a .rb file. I thought the equivalent of the '-n -e "print"'
one liner would be:

	while gets()

but, when I put this in a file called parser.rb and try

	type input.txt | parser.rb

I get the following:

	The process tried to write to a nonexistent pipe.
	c:/scripts/parser.rb:1:in `gets': Bad file descriptor
      	  from c:/scripts/parser.rb:1

Chris (Guest)
on 2006-05-18 22:02
Maybe its a Cygwin thing, the following:

type subseq.rb | ruby pipe-test.rb

works fine for me.

pipe-test.rb is :
can pipe to scipt on Win ??
i.e. dos>type file.txt | ruby -w pipe-test.rb
while gets()

Is the ruby a Cygwin build?
A LeDonne (Guest)
on 2006-05-18 22:25
(Received via mailing list)
On 5/18/06, Stuart H. <removed_email_address@domain.invalid> wrote:
>                 print
> (Errno::EBADF)
>           from c:/scripts/parser.rb:1
> Thanks,
> Stu

What happens if you do:

type input.txt | ruby parser.rb


I think the point may be that you have to call the ruby interpreter
explicitly, rather than relying on windows file associations to do the
right thing when there's a pipe involved.

Vrtwo L. (Guest)
on 2006-05-19 06:00
(Received via mailing list)
It's getting to ruby if a ruby exception is being thrown.

Does it work w/ perl or any other language? (just curious)  I would
think that it woudlnt.
Pit C. (Guest)
on 2006-05-19 11:54
(Received via mailing list)
A LeDonne schrieb:
> What happens if you do:
> type input.txt | ruby parser.rb

Thank you, this did it for me on Windows 2000 with the one click

   type r.rb | r.rb
   r.rb:1:in `readlines': Bad file descriptor (Errno::EBADF)

   type r.rb | ruby r.rb
   ["p ARGF.readlines\n"]

   r.rb r.rb
   ["p ARGF.readlines\n"]

This topic is locked and can not be replied to.