[lnkForumImage]
TotalShareware - Download Free Software

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


 

Forums >

comp.lang.ruby

pipelining

Fara Nasr

8/11/2007 11:39:00 PM

Hello everyone

I urgently some help with this code. I am trying to implement the
following pipeline and i keep getting this error Erro:ENOENT
can anybody please help me to get this code working


#input is the command line
def handleCommandLine(input)
# it splits the pipeline into an array
command = input.split('|').map{|c|word_list(c)}
i = 0
while i< command.length
commands = command.at(i)
execute(commands)
i +=1
end
end

def execute(commands)
rd, wr = IO.pipe
if fork.nil?
# child
rd.close
$stdout.reopen(wr)
wr.close
exec(*commands)
exit
else
# parent
wr.close
$stdin.reopen(rd)
rd.close
end
end
--
Posted via http://www.ruby-....

3 Answers

Tim Pease

8/12/2007 12:39:00 AM

0

On 8/11/07, Fara Nasr <faranak_code000@yahoo.com> wrote:
> Hello everyone
>
> I urgently some help with this code. I am trying to implement the
> following pipeline and i keep getting this error Erro:ENOENT
> can anybody please help me to get this code working
>

The error is most likely coming from the "exec" command in the forked
child process. It's telling you that one of your commands does not
exist.

Can you post the full error message? That might give some more insight
and a better answer (this is just my best guess).

Blessings,
TwP

PS In your child, call exit! instead of just plain exit. exit! will
prevent the at_exit routines from running and killing file descriptors
in the parent. See the documentation on fork for more details.


>
> #input is the command line
> def handleCommandLine(input)
> # it splits the pipeline into an array
> command = input.split('|').map{|c|word_list(c)}
> i = 0
> while i< command.length
> commands = command.at(i)
> execute(commands)
> i +=1
> end
> end
>
> def execute(commands)
> rd, wr = IO.pipe
> if fork.nil?
> # child
> rd.close
> $stdout.reopen(wr)
> wr.close
> exec(*commands)
> exit
> else
> # parent
> wr.close
> $stdin.reopen(rd)
> rd.close
> end
> end
> --
> Posted via http://www.ruby-....
>
>

Fara Nasr

8/12/2007 1:03:00 AM

0

Hi Tim,

All right, To illustrate what happens i have add a puts command to the
code ! the result is so bizzare!!!
Here is the code again:


def handleCommandLine(input)
#splits the command line
command = input.split('|').map{|c|word_list(c)}
i = 0
while i< command.length
commands = command.at(i)
puts commands , "...........\n"
execute(commands)
i +=1
end
end
def execute(commands)
rd, wr = IO.pipe
if fork.nil?
# child
rd.close
$stdout.reopen(wr)
wr.close
exec(*commands)
exit
else
# parent
wr.close
$stdin.reopen(rd)
rd.close
Process.wait
end
end



so i used this to test it

001>ls | grep D



here is the result!! the correct result must be 001>Desktop and it has
to stop there!!!




ls
...........
grep
D
...........
001>Desktop
...........
Test.rb:45:in `exec': No such file or directory - Desktop
(Errno::ENOENT)
from Test.rb:45:in `execute'
from Test.rb:32:in `handleCommandLine'
from Test.rb:20:in `run'
from Test.rb:17:in `loop'
from Test.rb:17:in `run'
from Test.rb:68


thanks a lot

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

james g. keegan jr.

1/26/2011 12:01:00 AM

0

In article
<740eabc4-9bbf-4661-9d59-129fa23d8ffb@u9g2000prm.googlegroups.com>,
william mosco <wm5772@gmail.com> wrote:

> On Jan 24, 3:26?pm, "james g. keegan jr." <jgkee...@gmail.com> wrote:
> > In article
> > <b01573dc-0152-4ed9-912c-4c1819acd...@j19g2000prh.googlegroups.com>,
> > ?william mosco <wm5...@gmail.com> wrote:
> >
> >
> >
> >
> >
> > > james g. keegan jr. wrote:
> > > > In article
> > > > <62f586b6-a653-4855-a2fd-a395969df...@l19g2000yqo.googlegroups.com>,
> > > > ?william mosco <wm5...@gmail.com> wrote:
> >
> > > > > On Jan 23, 8:31?pm, "james g. keegan jr." <jgkee...@gmail.com> wrote:
> > > > > > In article
> >
> > > > > > > i have little tolerance for those who think other people's
> > > > > > > property
> > > > > > > and rights are there's to deal with...
> >
> > > > > > you could have accurately ended your statement after the word
> > > > > > "tolerance." ha ha ha
> >
> > > > > ? i'm the most tolerant person you'd ever run into. ?charitable too,
> > > > > but only with my money, not yours.
> >
> > > > and here silly billy demonstrates that no matter how dumb and dishonest
> > > > he is that he occasionally has a sense of humor.
> >
> > > I never figured you'd buy it, or understand.
> >
> > everyone understood your self-depreciating joke, silly billy.
>
> so happy to hear you assume to speak for everyone, pompous one.

everyone knows that monday follows sunday, imbecile. you shouldn't use
words you don't understand.