JRuby (please use github issues at http://bugs.jruby.org)
  1. JRuby (please use github issues at http://bugs.jruby.org)
  2. JRUBY-5874

Kernel#` and Kernel#system didn't correctly glob when using ruby

    Details

    • Type: Bug Bug
    • Status: Resolved Resolved
    • Priority: Major Major
    • Resolution: Fixed
    • Affects Version/s: JRuby 1.6.2
    • Fix Version/s: JRuby 1.7.0.pre1
    • Component/s: None
    • Labels:
      None
    • Environment:
      (Java HotSpot(TM) 64-Bit Server VM 1.6.0_24) [darwin-x86_64-java]
    • Number of attachments :
      0

      Description

      I believe this is related to:
      http://jira.codehaus.org/browse/JRUBY-5873

      Kernel#` and Kernel#system can do glob correctly
      for any other process, but not for JRuby itself:

      >> `jruby test/test_*.rb`
      "Error opening script file: /Users/godfat/project/cardinalblue/rest-graph/test/test_*.rb (No such file or directory)\n"

      This makes my `jruby -S rake test` fail.
      I tried a while to find out the actual problem.

      Thank you for the fix!

        Activity

        Hide
        Hiro Asari added a comment - - edited

        Recall the discussion in JRUBY-5873; this happens because there is no globbing (which is done by the shell) when JRuby takes a shortcut inside back ticks. You can either be more explicit in listing the files, or spawn a new process with -J-Djruby.launch.inproc=false.

        Does this make sense?

        Show
        Hiro Asari added a comment - - edited Recall the discussion in JRUBY-5873 ; this happens because there is no globbing (which is done by the shell) when JRuby takes a shortcut inside back ticks. You can either be more explicit in listing the files, or spawn a new process with -J-Djruby.launch.inproc=false . Does this make sense?
        Hide
        Lin Jen-Shin added a comment -

        True, but since JRuby is already looking at the command before passing to shell, isn't it good if it can also expand the glob, just as other rubies..? Personally, I don't want to have switches in my code for JRuby.

        But maybe you're right, passing -J-Djruby.launch.inproc=true should solve all this. Or is it possible to emit some suggestion, just like asking user to install jruby-openssl, or like asking user to add -X+O to turn on ObjectSpace. It's helpful and people might not wonder if it's a bug or not anymore.

        Thanks for considering.

        Show
        Lin Jen-Shin added a comment - True, but since JRuby is already looking at the command before passing to shell, isn't it good if it can also expand the glob, just as other rubies..? Personally, I don't want to have switches in my code for JRuby. But maybe you're right, passing -J-Djruby.launch.inproc=true should solve all this. Or is it possible to emit some suggestion, just like asking user to install jruby-openssl, or like asking user to add -X+O to turn on ObjectSpace. It's helpful and people might not wonder if it's a bug or not anymore. Thanks for considering.
        Hide
        Hiro Asari added a comment -

        I do not doubt that -J-Djruby.launch.inproc=false gives you a more MRI-compatible behavior. But this is often (think running Specs, unit tests, etc.) too high a price to pay, since spinning up JVM is quite expensive. So the default is to be incompatible.

        JRuby's algorithm to make the decision on whether or not to run the "child" process inside or not is very limited to say the least. It means that it doesn't do any globbing, which can be quite hairy; for example,

        $ ls bench/bench_{io,loop,method}_[^to,for]*.rb
        bench/bench_io_gets.rb			bench/bench_loop_versus_while.rb
        bench/bench_io_sysread.rb		bench/bench_method_missing.rb
        

        If there is an easy way to account for all glob patterns, then it might be worth pursuing. But for now, it doesn't seem worthwhile.

        Show
        Hiro Asari added a comment - I do not doubt that -J-Djruby.launch.inproc=false gives you a more MRI-compatible behavior. But this is often (think running Specs, unit tests, etc.) too high a price to pay, since spinning up JVM is quite expensive. So the default is to be incompatible. JRuby's algorithm to make the decision on whether or not to run the "child" process inside or not is very limited to say the least. It means that it doesn't do any globbing, which can be quite hairy; for example, $ ls bench/bench_{io,loop,method}_[^to,for]*.rb bench/bench_io_gets.rb bench/bench_loop_versus_while.rb bench/bench_io_sysread.rb bench/bench_method_missing.rb If there is an easy way to account for all glob patterns, then it might be worth pursuing. But for now, it doesn't seem worthwhile.
        Hide
        Hiro Asari added a comment -

        Perhaps we could warn if we see *, ?, braces or square brackets. Is there any other special character in globbing?

        Show
        Hiro Asari added a comment - Perhaps we could warn if we see * , ? , braces or square brackets. Is there any other special character in globbing?
        Hide
        Lin Jen-Shin added a comment -

        A warning is fine for me.

        As for when to warn, is it possible to emit the warning whenever JRuby tries to reuse the existing JVM, no matter if the user wants glob or not? Since this is already an incompatibility, it would be good if users from other rubies could be aware of this special case in JRuby.

        Thanks!

        On the other hand, this is off topic, but I hope people can start writing tests without using Rake to invoke shells. I changed all my tests running inside the process running Rake instead of using shells. I guess this is really what we want, so that we can pass Ruby options as normal.

        Show
        Lin Jen-Shin added a comment - A warning is fine for me. As for when to warn, is it possible to emit the warning whenever JRuby tries to reuse the existing JVM, no matter if the user wants glob or not? Since this is already an incompatibility, it would be good if users from other rubies could be aware of this special case in JRuby. Thanks! On the other hand, this is off topic, but I hope people can start writing tests without using Rake to invoke shells. I changed all my tests running inside the process running Rake instead of using shells. I guess this is really what we want, so that we can pass Ruby options as normal.
        Hide
        Hiro Asari added a comment -

        I'm not sure if we should warn on all occasions. I think it would be too noisy.

        I put in the warning to the master. https://github.com/jruby/jruby/commit/2ebb5799eff5d7d0dddf88cbfda9130c09f0f2b0

        Testing habits are hard to change, unfortunately.

        Resolving.

        Show
        Hiro Asari added a comment - I'm not sure if we should warn on all occasions. I think it would be too noisy. I put in the warning to the master. https://github.com/jruby/jruby/commit/2ebb5799eff5d7d0dddf88cbfda9130c09f0f2b0 Testing habits are hard to change, unfortunately. Resolving.
        Hide
        Lin Jen-Shin added a comment -

        Thank you!

        Show
        Lin Jen-Shin added a comment - Thank you!

          People

          • Assignee:
            Hiro Asari
            Reporter:
            Lin Jen-Shin
          • Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved: