[ANN] open4-0.2.0

Discussion in 'Ruby' started by ara.t.howard@noaa.gov, Feb 14, 2006.

  1. Guest

    URIS

    http://rubyforge.org/frs/?group_id=1024
    http://www.codeforpeople.com/lib/ruby/


    SYNOPSIS

    open child process with handles on pid, stdin, stdout, and stderr


    HISTORY

    0.2.0 :
    - added exception marshaled from child -> parent when exec fails. thanks
    to jordan breeding for a patch (yay!) and paul brannan for this most
    excellent idea.

    0.1.0 :
    - fixed docs to correctly show return value of popen4 (pid first not last).
    thanks Stefanie Tellex <> for catching this.
    0.0.0 :
    - initial version


    INSTALL

    ~> gem install open4


    SAMPLES

    simple usage:

    jib:~/eg/ruby/open4/open4-0.2.0 > cat sample/simple.rb
    require "open4"

    pid, stdin, stdout, stderr = Open4::popen4 "sh"

    stdin.puts "echo 42.out"
    stdin.puts "echo 42.err 1>&2"
    stdin.close

    ignored, status = Process::waitpid2 pid

    puts "pid : #{ pid }"
    puts "stdout : #{ stdout.read.strip }"
    puts "stderr : #{ stderr.read.strip }"
    puts "status : #{ status.inspect }"
    puts "exitstatus : #{ status.exitstatus }"


    jib:~/eg/ruby/open4/open4-0.2.0 > ruby sample/simple.rb
    pid : 17273
    stdout : 42.out
    stderr : 42.err
    status : #<Process::Status: pid=17273,exited(0)>
    exitstatus : 0


    block form - child process is automatically waited for:


    jib:~/eg/ruby/open4/open4-0.2.0 > cat sample/block.rb
    require 'open4'

    status =
    Open4::popen4("sh") do |pid, stdin, stdout, stderr|
    stdin.puts "echo 42.out"
    stdin.puts "echo 42.err 1>&2"
    stdin.close

    puts "pid : #{ pid }"
    puts "stdout : #{ stdout.read.strip }"
    puts "stderr : #{ stderr.read.strip }"
    end

    puts "status : #{ status.inspect }"
    puts "exitstatus : #{ status.exitstatus }"


    jib:~/eg/ruby/open4/open4-0.2.0 > ruby sample/block.rb
    pid : 17295
    stdout : 42.out
    stderr : 42.err
    status : #<Process::Status: pid=17295,exited(0)>
    exitstatus : 0


    exceptions are marshaled from child to parent if fork/exec fails:


    jib:~/eg/ruby/open4/open4-0.2.0 > cat sample/exception.rb
    require "open4"
    Open4::popen4 "noexist"


    jib:~/eg/ruby/open4/open4-0.2.0 > ruby sample/exception.rb
    /dmsp/reference/ruby-1.8.1//lib/ruby/site_ruby/open4.rb:100:in `popen4': No such file or directory - noexist (Errno::ENOENT)
    from sample/exception.rb:3


    AUTHOR




    LICENSE

    ruby's


    enjoy.


    -a

    --
    judge your success by what you had to give up in order to get it.
    - h.h. the 14th dali lama
     
    , Feb 14, 2006
    #1
    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. [ANN] open4-0.5.0

    , Aug 8, 2006, in forum: Ruby
    Replies:
    0
    Views:
    86
  2. [ANN] open4-0.5.1

    , Aug 22, 2006, in forum: Ruby
    Replies:
    0
    Views:
    115
  3. [ANN] open4-0.6.0

    , Aug 31, 2006, in forum: Ruby
    Replies:
    0
    Views:
    85
  4. [ANN] open4-0.7.0

    , Sep 1, 2006, in forum: Ruby
    Replies:
    0
    Views:
    74
  5. [ANN] open4-0.8.0

    , Sep 25, 2006, in forum: Ruby
    Replies:
    2
    Views:
    110
Loading...

Share This Page