[ANN] open4-0.2.0

A

ara.t.howard

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 <[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

(e-mail address removed)


LICENSE

ruby's


enjoy.


-a
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads

open4 stdin.close required? 0
[ANN] open4-0.9.2 0
[ANN] open4-0.8.0 2
[ANN] open4-0.9.0 0
[ANN] open4-0.6.0 0
[ANN] open4-0.5.1 0
[ANN] open4-0.5.0 0
[ANN] open4-0.7.0 0

Members online

No members online now.

Forum statistics

Threads
473,967
Messages
2,570,148
Members
46,694
Latest member
LetaCadwal

Latest Threads

Top