Skip to content

Commit

Permalink
Improve shell+cmd checking and inherit stderr from parent.
Browse files Browse the repository at this point in the history
Fixes #1396.
  • Loading branch information
headius committed May 7, 2015
1 parent 2799836 commit 0505de3
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
2 changes: 1 addition & 1 deletion core/src/main/java/org/jruby/util/ShellLauncher.java
Original file line number Diff line number Diff line change
Expand Up @@ -1619,7 +1619,7 @@ private static String getShell(Ruby runtime) {
return RbConfigLibrary.jrubyShell();
}

private static boolean shouldUseShell(String command) {
public static boolean shouldUseShell(String command) {
boolean useShell = false;
for (char c : command.toCharArray()) {
if (c != ' ' && !Character.isLetter(c) && "*?{}[]<>()~&|\\$;'`\"\n".indexOf(c) != -1) {
Expand Down
7 changes: 6 additions & 1 deletion core/src/main/ruby/jruby/kernel/jruby/process_manager.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ module ProcessManager
java_import org.jruby.util.ShellLauncher
java_import java.lang.ProcessBuilder
java_import org.jruby.runtime.builtin.IRubyObject
java_import org.jruby.platform.Platform

Redirect = ProcessBuilder::Redirect
LaunchConfig = ShellLauncher::LaunchConfig
Expand All @@ -18,14 +19,18 @@ def self.`(command)

config = LaunchConfig.new(JRuby.runtime, [command].to_java(IRubyObject), false)

if config.should_run_in_shell?
use_shell = Platform::IS_WINDOWS ? config.should_run_in_shell : false
use_shell |= ShellLauncher.should_use_shell(command)

if use_shell
config.verify_executable_for_shell
else
config.verify_executable_for_direct
end

pb = ProcessBuilder.new(config.exec_args)
pb.redirect_input(Redirect::INHERIT)
pb.redirect_error(Redirect::INHERIT)
pb.environment(ShellLauncher.get_current_env(JRuby.runtime))
pb.directory(JFile.new(JRuby.runtime.current_directory))
process = pb.start
Expand Down

0 comments on commit 0505de3

Please sign in to comment.