def popen_foo(env={}, cmd)
      if IO.respond_to? :popen4
        # setting the env is broken in jruby
        args = ['env -i', escape_opts(env), cmd]
        IO.popen4(args.join(' ')) do |_pid, *yield_args|
          yield *yield_args
        end
        return $?
      else
        Open3.popen3(env, cmd,:unsetenv_others => true ) do |*yield_args,_thr|
          yield *yield_args
          return _thr.value
        end
      end
    end
def popen_foo(env={}, cmd)
      if IO.respond_to? :popen4
        # setting the env is broken in jruby
        args = ['env -i', escape_opts(env), cmd]
        IO.popen4(args.join(' ')) do |_pid, *yield_args|
          yield *yield_args
        end
        return $?
      else
        Open3.popen3(env, cmd,:unsetenv_others => true ) do |*yield_args,_thr|
          yield *yield_args
          return _thr.value
        end
      end
    end
@api private

 popen3 is broken in jruby, popen4 is not available in mri :(