diff --git a/lib/open3.rb b/lib/open3.rb index 2f035e3bcd..9652b27194 100644 --- a/lib/open3.rb +++ b/lib/open3.rb @@ -31,12 +31,8 @@ require 'open3/version' -if RUBY_ENGINE == 'jruby' && JRuby::Util::ON_WINDOWS - require_relative 'open3/jruby_windows' - return -end - module Open3 + # Open stdin, stdout, and stderr streams and start external executable. # In addition, a thread to wait for the started process is created. # The thread has a pid method and a thread variable :pid which is the pid of @@ -763,3 +759,6 @@ module Open3 end end + +# JRuby uses different popen logic on Windows, require it here to reuse wrapper methods above. +require 'open3/jruby_windows' if RUBY_ENGINE == 'jruby' && JRuby::Util::ON_WINDOWS diff --git a/lib/open3/jruby_windows.rb b/lib/open3/jruby_windows.rb index 24b9a1ba7e..064c38b597 100644 --- a/lib/open3/jruby_windows.rb +++ b/lib/open3/jruby_windows.rb @@ -57,6 +57,15 @@ module Open3 module_function :popen2e def processbuilder_run(cmd, opts, build: nil, io:) + opts.each do |k, v| + if Integer === k + if IO == v || !(String === v || v.respond_to?(:to_path)) + # target is an open IO or a non-pathable object, bail out + raise NotImplementedError.new("redirect to an open IO is not implemented on this platform") + end + end + end + if Hash === cmd[0] env = cmd.shift; else