Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Ruby > [ANN] open4-0.2.0

Reply
Thread Tools

[ANN] open4-0.2.0

 
 
ara.t.howard@noaa.gov
Guest
Posts: n/a
 
      02-14-2006
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:open4 "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:open4("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:open4 "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


 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off




Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57