pipelining

Discussion in 'Ruby' started by Fara Nasr, Aug 12, 2007.

  1. Fara Nasr

    Fara Nasr Guest

    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-forum.com/.
     
    Fara Nasr, Aug 12, 2007
    #1
    1. Advertising

  2. Fara Nasr

    Tim Pease Guest

    On 8/11/07, Fara Nasr <> 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-forum.com/.
    >
    >
     
    Tim Pease, Aug 12, 2007
    #2
    1. Advertising

  3. Fara Nasr

    Fara Nasr Guest

    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-forum.com/.
     
    Fara Nasr, Aug 12, 2007
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. koko

    Pipelining in VHDL

    koko, Apr 29, 2004, in forum: VHDL
    Replies:
    2
    Views:
    5,731
    mizocom
    Apr 29, 2004
  2. Peggy
    Replies:
    0
    Views:
    648
    Peggy
    Sep 8, 2004
  3. tulip

    pipelining

    tulip, Nov 5, 2004, in forum: VHDL
    Replies:
    0
    Views:
    653
    tulip
    Nov 5, 2004
  4. Andrea Campi

    Pipelining tutorial wanted

    Andrea Campi, Nov 14, 2004, in forum: VHDL
    Replies:
    9
    Views:
    2,229
    Mike Treseler
    Nov 19, 2004
  5. Divyang M
    Replies:
    3
    Views:
    621
    David Bishop
    Feb 4, 2005
Loading...

Share This Page