# Re: Command Line Processing / Pipes

**URL:** <https://www.ruby-forum.com/t/re-command-line-processing-pipes/94974>\
**Category:** Ruby\
**Created:** [May 18, 2006, 5:02pm UTC](https://www.ruby-forum.com/t/re-command-line-processing-pipes/94974 "2006-05-18T17:02:54Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![stuart\_holden](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/7993a0/32.png) [@stuart\_holden](https://www.ruby-forum.com/u/stuart_holden)\
**Post date:** [May 18, 2006, 5:02pm UTC](https://www.ruby-forum.com/t/re-command-line-processing-pipes/94974/1 "2006-05-18T17:02:54Z")

</div>

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()
	print
end

```

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

```

(Errno::EBADF)  
from c:/scripts/parser.rb:1

Thanks,  
Stu

---

<div class="post-metadata">

**Author:** ![stuart\_holden](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/7993a0/32.png) [@stuart\_holden](https://www.ruby-forum.com/u/stuart_holden)\
**Post date:** [May 18, 2006, 8:02pm UTC](https://www.ruby-forum.com/t/re-command-line-processing-pipes/94974/2 "2006-05-18T20:02:07Z")

</div>

Maybe its a Cygwin thing, the following:

type subseq.rb | ruby pipe-test.rb

works fine for me.

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

Is the ruby a Cygwin build?

---

<div class="post-metadata">

**Author:** ![stuart\_holden](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/7993a0/32.png) [@stuart\_holden](https://www.ruby-forum.com/u/stuart_holden)\
**Post date:** [May 18, 2006, 8:25pm UTC](https://www.ruby-forum.com/t/re-command-line-processing-pipes/94974/3 "2006-05-18T20:25:48Z")

</div>

On 5/18/06, Stuart H. [removed\_email\_address@domain.invalid](mailto: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.

-A

---

<div class="post-metadata">

**Author:** ![stuart\_holden](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/7993a0/32.png) [@stuart\_holden](https://www.ruby-forum.com/u/stuart_holden)\
**Post date:** [May 19, 2006, 4:00am UTC](https://www.ruby-forum.com/t/re-command-line-processing-pipes/94974/4 "2006-05-19T04:00:14Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![stuart\_holden](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/7993a0/32.png) [@stuart\_holden](https://www.ruby-forum.com/u/stuart_holden)\
**Post date:** [May 19, 2006, 9:54am UTC](https://www.ruby-forum.com/t/re-command-line-processing-pipes/94974/5 "2006-05-19T09:54:36Z")

</div>

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  
installer:

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”]

Regards,  
Pit
