Module | POpen4 |
In: |
lib/popen4.rb
|
POpen4 provides the Rubyist a single API across platforms for executing a command in a child process with handles on stdout, stderr, and stdin streams as well as access to the process ID and exit status.
Consider the following example (borrowed from Open4):
require 'rubygems' require 'popen4' status = POpen4::popen4("cmd") do |stdout, stderr, stdin, pid| stdin.puts "echo hello world!" stdin.puts "echo ERROR! 1>&2" stdin.puts "exit" stdin.close puts "pid : #{ pid }" puts "stdout : #{ stdout.read.strip }" puts "stderr : #{ stderr.read.strip }" end puts "status : #{ status.inspect }" puts "exitstatus : #{ status.exitstatus }"
Starts a new process and hands IO objects representing the subprocess stdout, stderr, stdin streams and the pid (respectively) to the block supplied. If the command could not be started, return nil.
The mode argument may be set to t[ext] or b[inary] and is used only on Windows platforms.
The stdin stream and/or pid may be omitted from the block parameter list if they are not required.