tags:

views:

271

answers:

2

Ruby's standard popen3 module does not work on Windows. Is there a maintained replacement that allows for separating stdin, stdout, and stderr?

+3  A: 

POpen4 has a common interface between unix and Windows. The following example (from their website) works like a charm.

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 }"
Max Caceres
A: 

popen3 works with MRI 1.9.x on windows.

rogerdpack