diff --git a/src/org/jruby/RubyKernel.java b/src/org/jruby/RubyKernel.java index 7c83c5595de..94770078827 100644 --- a/src/org/jruby/RubyKernel.java +++ b/src/org/jruby/RubyKernel.java @@ -1667,7 +1667,7 @@ private static RubyNumeric randCommon(ThreadContext context, Ruby runtime, Rando @JRubyMethod(name = "spawn", required = 1, rest = true, module = true, visibility = PRIVATE, compat = RUBY1_9) public static RubyFixnum spawn(ThreadContext context, IRubyObject recv, IRubyObject[] args) { Ruby runtime = context.getRuntime(); - long pid = ShellLauncher.runWithoutWait(runtime, args); + long pid = ShellLauncher.runExternalWithoutWait(runtime, args); return RubyFixnum.newFixnum(runtime, pid); } diff --git a/src/org/jruby/RubyProcess.java b/src/org/jruby/RubyProcess.java index 0057fd32924..39ce3f40c37 100644 --- a/src/org/jruby/RubyProcess.java +++ b/src/org/jruby/RubyProcess.java @@ -950,7 +950,7 @@ public static IRubyObject fork(ThreadContext context, IRubyObject recv, Block bl @JRubyMethod(name = "spawn", required = 1, rest = true, module = true, compat = CompatVersion.RUBY1_9) public static RubyFixnum spawn(ThreadContext context, IRubyObject recv, IRubyObject[] args) { Ruby runtime = context.getRuntime(); - long pid = ShellLauncher.runWithoutWait(runtime, args); + long pid = ShellLauncher.runExternalWithoutWait(runtime, args); return RubyFixnum.newFixnum(runtime, pid); } diff --git a/src/org/jruby/util/ShellLauncher.java b/src/org/jruby/util/ShellLauncher.java index 353c7ea76a2..82993ac9e51 100644 --- a/src/org/jruby/util/ShellLauncher.java +++ b/src/org/jruby/util/ShellLauncher.java @@ -371,6 +371,10 @@ public static long runWithoutWait(Ruby runtime, IRubyObject[] rawArgs) { return runWithoutWait(runtime, rawArgs, runtime.getOutputStream()); } + public static long runExternalWithoutWait(Ruby runtime, IRubyObject[] rawArgs) { + return runWithoutWait(runtime, rawArgs, runtime.getOutputStream()); + } + public static int execAndWait(Ruby runtime, IRubyObject[] rawArgs) { File pwd = new File(runtime.getCurrentDirectory()); LaunchConfig cfg = new LaunchConfig(runtime, rawArgs, true); @@ -414,7 +418,7 @@ public static int runAndWait(Ruby runtime, IRubyObject[] rawArgs, OutputStream o } } - public static long runWithoutWait(Ruby runtime, IRubyObject[] rawArgs, OutputStream output) { + private static long runWithoutWait(Ruby runtime, IRubyObject[] rawArgs, OutputStream output) { OutputStream error = runtime.getErrorStream(); try { Process aProcess = run(runtime, rawArgs, true); @@ -425,6 +429,17 @@ public static long runWithoutWait(Ruby runtime, IRubyObject[] rawArgs, OutputStr } } + private static long runExternalWithoutWait(Ruby runtime, IRubyObject[] rawArgs, OutputStream output) { + OutputStream error = runtime.getErrorStream(); + try { + Process aProcess = run(runtime, rawArgs, true, true); + handleStreamsNonblocking(runtime, aProcess, output, error); + return getPidFromProcess(aProcess); + } catch (IOException e) { + throw runtime.newIOErrorFromException(e); + } + } + public static long getPidFromProcess(Process process) { if (process instanceof ScriptThreadProcess) { return process.hashCode(); @@ -1119,12 +1134,16 @@ private static boolean shouldVerifyPathExecutable(String cmdline) { } public static Process run(Ruby runtime, IRubyObject[] rawArgs, boolean doExecutableSearch) throws IOException { + return run(runtime, rawArgs, doExecutableSearch, false); + } + + public static Process run(Ruby runtime, IRubyObject[] rawArgs, boolean doExecutableSearch, boolean forceExternalProcess) throws IOException { Process aProcess = null; File pwd = new File(runtime.getCurrentDirectory()); LaunchConfig cfg = new LaunchConfig(runtime, rawArgs, doExecutableSearch); try { - if (cfg.shouldRunInProcess()) { + if (!forceExternalProcess && cfg.shouldRunInProcess()) { log(runtime, "Launching in-process"); ScriptThreadProcess ipScript = new ScriptThreadProcess( runtime, cfg.getExecArgs(), getCurrentEnv(runtime), pwd);