Command Line Processing / Pipes

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

···

-----Original Message-----
From: list-bounce@example.com [mailto:list-bounce@example.com] On Behalf
Of Chris
Sent: 18 May 2006 14:23
To: ruby-talk ML
Subject: Re: Command Line Processing / Pipes

The following works on Win2k with ruby 1.8.2 (2004-12-25) [i386-mswin32]

type save_sql_env.txt | ruby -n -e "print"

I use 'type' as 'cat' is not a windows command in Win2k

--
Posted via http://www.ruby-forum.com/\.

<body>

<blockquote>
<font FACE="Arial,Arial" SIZE="1"><p ALIGN="JUSTIFY">This Email may contain confidential and privileged information and is intended for the use of the addressee(s) only. If you are not the intended recipient please notify the sender and delete the Email from your system. It should not be transmitted to any other person without the consent of the sender. Additional important notifications regarding Email transmissions from and to members of Baring Asset Management can be accessed at <a href="http://www.barings.com/email/index.hcst&quot;&gt;http://www.barings.com/email/index.hcst&lt;/a&gt;&lt;/font&gt;&lt;/p&gt;&lt;/body&gt;
</p>
</font>
</blockquote>

<p>&nbsp;</p>
</body>
</html>

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?

···

--
Posted via http://www.ruby-forum.com/.

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

···

On 5/18/06, Stuart Holden <Stuart.Holden@baring-asset.com> wrote:

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

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.

···

On 5/18/06, A LeDonne <aledonne.listmail@gmail.com> wrote:

On 5/18/06, Stuart Holden <Stuart.Holden@baring-asset.com> wrote:
> 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
>

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

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