module POpen4

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 }"