[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

Piping problem

Pawel Radecki

11/24/2007 4:53:00 PM

Hello everybody!

I'm trying to write a simple program that reads text from standard input
and writes text to standard output. The source code is as follows:

#!/usr/bin/env ruby
text = ""
while (line = gets)
text+=line
end
print text.reverse


Now I want to execute it on the Windows XP box with a pipe to redirect
results so I know that:

reverse.rb sample.txt | reverse.rb

will show me (on the screen be default) the contents of sample.txt file
in non-reversed way.
I'm executing above command line and getting this:

reverse.rb:9:in 'gets': Bad file descriptor (Errno:EBADF)


Do you have any ideas why it doesn't work?

Thanks in advance for any help!


--
Pawel Radecki
m: +48 695 34-64-76
e: pawel.j.radecki@gmail.com
w: http://radeckimarch.blo...

9 Answers

7stud --

11/25/2007 12:19:00 AM

0

Pawel Radecki wrote:
> Hello everybody!
>
> I'm trying to write a simple program that reads text from standard input
> and writes text to standard output. The source code is as follows:
>
> #!/usr/bin/env ruby
> text = ""
> while (line = gets)
> text+=line
> end
> print text.reverse
>
>
> Now I want to execute it on the Windows XP box with a pipe to redirect
> results so I know that:
>
> reverse.rb sample.txt | reverse.rb
>
> will show me (on the screen be default) the contents of sample.txt file
> in non-reversed way.
> I'm executing above command line and getting this:
>
> reverse.rb:9:in 'gets': Bad file descriptor (Errno:EBADF)
>
>
> Do you have any ideas why it doesn't work?
>
> Thanks in advance for any help!

When I get that error, it usually means that I am trying to read(e.g.
gets) from something that is opened for writing only. I'm not sure how
knowing that is useful in this case.

Isn't the command:

reverse.rb sample.txt | reverse.rb

equivalent to:

cat sample.txt

??
--
Posted via http://www.ruby-....

7stud --

11/25/2007 12:22:00 AM

0

I forgot to say, your command works for me on mac os x(unix):

$ cat data.txt
hello world
goodbye

$ r5test.rb data.txt | r5test.rb
hello world
goodbye

$
--
Posted via http://www.ruby-....

7stud --

11/25/2007 12:25:00 AM

0

7stud -- wrote:
> I forgot to say, your command works for me on mac os x(unix):
>
> $ cat data.txt
> hello world
> goodbye
>
> $ r5test.rb data.txt | r5test.rb
> hello world
> goodbye
>
> $

This probably better illustrates what I'm seeing:

$ cat data.txt
hello world
goodbye
$ r5test.rb data.txt

eybdoog
dlrow olleh$ r5test.rb data.txt | r5test.rb
hello world
goodbye
$

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

MonkeeSage

11/25/2007 5:18:00 AM

0

On Nov 24, 10:52 am, Pawel Radecki <pawel.j.rade...@gmail.com> wrote:

> Now I want to execute it on the Windows XP box with a pipe to redirect
> results so I know that:
>
> reverse.rb sample.txt | reverse.rb

Well, you've defined reverse.rb to read from stdin, but you're passing
it a file with no stdin. I think in XP there is a "type" command that
does what "cat" does on posix systems (outputs contents of file to
stdout), so I think you want this:

type sample.txt | reverse.rb | reverse.rb

I don't have an XP box to test on, but that works with "cat" on linux.
(Ps. Does XP's cmd.exe support pipes "|"? Or are you using cygwin or
something similar? (If so, you may have a version of "cat"
available.))

Regards,
Jordan



7stud --

11/25/2007 5:31:00 AM

0

Jordan Callicoat wrote:
> Well, you've defined reverse.rb to read from stdin,

Read the documentation for gets.


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

MonkeeSage

11/25/2007 6:59:00 AM

0

On Nov 24, 11:30 pm, 7stud -- <bbxx789_0...@yahoo.com> wrote:

> Read the documentation for gets.

Yeah, I probably should RTFM before I reply, heh.

> Returns (and assigns to +$_+) the next line from the list of files
> in +ARGV+ (or +$*+), or from standard input if no files are present
> on the command line.

Doh.

Regards,
Jordan

TerryP

11/25/2007 7:12:00 AM

0

Pawel Radecki wrote:
>
> #!/usr/bin/env ruby
> text = ""
> while (line = gets)
> text+=line
> end
> print text.reverse
>

Interestingly it seems to work perfectly fine here,

Terry@Dixie$ ruby --version
7:10
ruby 1.8.6 (2007-03-13 patchlevel 0) [i386-freebsd6]
Terry@Dixie$
7:11


botp

11/26/2007 1:25:00 AM

0

On Nov 25, 2007 12:52 AM, Pawel Radecki >
> reverse.rb:9:in 'gets': Bad file descriptor (Errno:EBADF)
> Do you have any ideas why it doesn't work?

>ruby -v
ruby 1.8.6 (2007-09-24 patchlevel 111) [i386-mswin32]

>ruby reverse.rb sample.txt | ruby reverse.rb
testing only

kind regards -botp

BeeSting Alergy

11/3/2013 6:17:00 PM

0

Tom the Lesser wrote:
> On Saturday, November 2, 2013 4:43:38 PM UTC-4, BeeSting Alergy wrote:
> > Is there ANYWHERE in the 1st Amendment that says anything about
> > "Separation of Church and State", blockhead?
> >
> > I see that you're too chickenshit...
>
> Wow. Because it took me 16 hours to reply to your stupid posts, I'm
> a "chicketshit"?

Wow. Are you stupid. I wasn't talking about a reply, you dumb piece of
shit. I was talking about this: Is there ANYWHERE in the 1st Amendment
that says anything about "Separation of Church and State", blockhead?

> I have a Life you know. I don't live on Usenet like some of your
> far-right KooKs do.

I've read enuf posts from you to know that YOU DO live on USENET.

> HA HA!!!

You find that you don't have a life funny, do you?

> > ... to actually post the text.
>
> It isn't the text, you willfully-ignorant and -stupid Ko0K. It is
> the concept.

Well, why did YOU bring up the 1st Amendment & "Separation of Church
and State"?

> Did you find the Right to Privacy our U.S. Supreme Court has
> repeatedly ruled is Constituional-protected yet?

Changing the subject is a sign of a moron & a coward, Tom the Lesser.

<*moronic rantings from a ne'er?do?well clipped*>

Repeating my question: Is there ANYWHERE in the 1st Amendment that says
anything about "Separation of Church and State", shit4brains?

Don't change the subject this time, idiot.

Just so you know.