On Sat, Dec 30, 2006 at 05:26:02AM +0900, ara.t.howard / noaa.gov wrote:
> On Sat, 30 Dec 2006, Mauricio Fernandez wrote:
> >On Sat, Dec 30, 2006 at 04:42:45AM +0900, Hemant Kumar wrote:
> >>Awesome work, has this been tested in Windows too?
> >
> >Some people tried to use xmpfilter on win32 and there were some issues but 
> >I believe they've been solved now (the code was modified so that it doesn't
> >require Kernel#fork/Open3::popen3 anymore, and some other problems were
> >addressed). If it doesn't work right now, I'm confident it can be fixed
> >easily, so just give it a try and we'll try to solve problems as they
> >appear.
> 
> did you switch from Open3::popen3 to systemu by chance?

I just needed the stdout/stderr of a ruby interpreter, so instead of this:

  def execute_popen(code)
    require 'open3'
    stdin, stdout, stderr = Open3::popen3(*interpreter_command)
    stdin.puts code
    @evals.each{|x| stdin.puts x } unless @evals.empty?
    stdin.close
    [stdout, stderr]
  end

win32 uses this code (thanks to eao197 for reporting & fixing the problem with
open files not being removable on win32):

  def execute_tmpfile(code)
    stdin, stdout, stderr = (1..3).map do |i|
      fname = "xmpfilter.tmpfile_#{Process.pid}-#{i}.rb"
      f = File.open(fname, "w+")
      at_exit { f.close unless f.closed?; File.unlink fname }
      f
    end
    stdin.puts code
    stdin.close
    exe_line = <<-EOF.map{|l| l.strip}.join(";")
      $stdout.reopen('#{stdout.path}', 'w')
      $stderr.reopen('#{stderr.path}', 'w')
      $0.replace '#{stdin.path}'
      ARGV.replace(#{@options.inspect})
      load #{stdin.path.inspect}
      #{@evals.join(";")}
    EOF
    system(*(interpreter_command << "-e" << exe_line))
    [stdout, stderr]
  end

-- 
Mauricio Fernandez  -   http://eigenclass.org   -  singular Ruby