Skip to content

Commit

Permalink
use user.dir as CWD when code is inside a jar on backquote execution
Browse files Browse the repository at this point in the history
when inside a jar the CWD is uri:classloader:/ and executing a system
command can not change into this CWD. use java system property user.dir
in such a case

Sponsored by Lookout Inc.
mkristian committed Jul 6, 2015
1 parent d0a2955 commit 1fd27e6
Showing 2 changed files with 15 additions and 1 deletion.
3 changes: 2 additions & 1 deletion core/src/main/ruby/jruby/kernel/jruby/process_manager.rb
Original file line number Diff line number Diff line change
@@ -32,7 +32,8 @@ def self.`(command)
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))
cwd = JRuby.runtime.current_directory.start_with?('uri:classloader:/') ? ENV_JAVA['user.dir'] : JRuby.runtime.current_directory
pb.directory(JFile.new(cwd))
process = pb.start

pid = ShellLauncher.reflect_pid_from_process(process)
13 changes: 13 additions & 0 deletions test/test_backquote.rb
Original file line number Diff line number Diff line change
@@ -13,6 +13,19 @@ def test_backquote_special_commands
end
end

def test_backquote_special_commands_and_cwd_inside_classloader
if File.exists?("/bin/echo")
begin
cwd = Dir.pwd
Dir.chdir('uri:classloader:/')
output = `/bin/echo hello`
assert_equal("hello\n", output)
ensure
Dir.chdir(cwd)
end
end
end

def test_system_special_commands
if File.exists?("/bin/true")
assert(system("/bin/true"))

0 comments on commit 1fd27e6

Please sign in to comment.