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 T. [email protected] 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