Skip to content

Commit 73f986c

Browse files
committed
Update to match JRuby 9.4
This allows the wrapper functions in the main open3 to be defined while using our ProcessBuilder logic for the internal popen implementation. Note this adds logic to reject redirects from a numeric fd to a live IO object (or not a String or to_path object) since we cannot support direct IO redirects with ProcesBuilder. This patch allows tests to complete with the ProcessBuilder impl. Only three tests fail: * test_numeric_file_descriptor2 and test_numeric_file_descriptor2 fail due to redirecting streams to a pipe IO. * test_pid fails expecting a real PID which we cannot provide via ProcessBuilder.
1 parent 7ca7f33 commit 73f986c

File tree

2 files changed

+13
-5
lines changed

2 files changed

+13
-5
lines changed

lib/open3.rb

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -31,12 +31,8 @@
3131

3232
require 'open3/version'
3333

34-
if RUBY_ENGINE == 'jruby' && JRuby::Util::ON_WINDOWS
35-
require_relative 'open3/jruby_windows'
36-
return
37-
end
38-
3934
module Open3
35+
4036
# Open stdin, stdout, and stderr streams and start external executable.
4137
# In addition, a thread to wait for the started process is created.
4238
# The thread has a pid method and a thread variable :pid which is the pid of
@@ -763,3 +759,6 @@ class << self
763759
end
764760

765761
end
762+
763+
# JRuby uses different popen logic on Windows, require it here to reuse wrapper methods above.
764+
require 'open3/jruby_windows' if RUBY_ENGINE == 'jruby' && JRuby::Util::ON_WINDOWS

lib/open3/jruby_windows.rb

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,15 @@ def popen2e(*cmd, &block)
5757
module_function :popen2e
5858

5959
def processbuilder_run(cmd, opts, build: nil, io:)
60+
opts.each do |k, v|
61+
if Integer === k
62+
if IO == v || !(String === v || v.respond_to?(:to_path))
63+
# target is an open IO or a non-pathable object, bail out
64+
raise NotImplementedError.new("redirect to an open IO is not implemented on this platform")
65+
end
66+
end
67+
end
68+
6069
if Hash === cmd[0]
6170
env = cmd.shift;
6271
else

0 commit comments

Comments
 (0)