comspec = ENV['COMSPEC']      # for mswin32
STDIN.binmode

len = STDIN.sysread(8).to_i
out = STDIN.sysread(len)
STDOUT.reopen(open(out, "w"))

len = STDIN.sysread(8).to_i
err = STDIN.sysread(len)
STDERR.reopen(open(err, "w"))

len  = STDIN.sysread(8).to_i
dump = STDIN.sysread(len)
hash = Marshal.restore(dump)
ENV.keys.each{|name| ENV.delete(name) }
hash.each{|k, v| ENV[k] = v if v }

dir = File::dirname(ENV["SCRIPT_FILENAME"])
Dir::chdir dir
if comspec && /mingw|mswin/ =~ RUBY_PLATFORM
  # I don't know the correct way to execute CGI scripts on win32.
  system(comspec, "/c", ENV['SCRIPT_FILENAME'])
  exit
end
exec ENV["SCRIPT_FILENAME"]
