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

Kernel.exec, Process.spawn (and IO.popen etc.) raise error when program is an array containing two strings

    Details

    • Type: Bug Bug
    • Status: Closed Closed
    • Priority: Major Major
    • Resolution: Incomplete
    • Affects Version/s: JRuby 1.7.0.pre1
    • Fix Version/s: None
    • Component/s: None
    • Labels:
      None
    • Number of attachments :
      0

      Description

      Kernel.exec, Process.spawn (and related methods such as IO.popen) raise error when program is an array containing two String objects.

      for example,

      % jruby -v -e 'exec(["/bin/ls", "XXX"])'
      jruby 1.7.0.preview1 (ruby-1.9.3-p203) (2012-05-19 00c8c98) (OpenJDK 64-Bit Server VM 1.6.0_20) [linux-amd64-java]
      Errno::ENOENT: No such file or directory - XXX
      _exec_internal at org/jruby/RubyKernel.java:1612
      exec at file:/PPPPPPP/jruby-1.7.0.preview1/lib/jruby.jar!/jruby/kernel19/kernel.rb:23
      (root) at -e:1

      % jruby -v -e 'Process.waitpid Process.spawn(["/bin/ls", "XXX"])'
      jruby 1.7.0.preview1 (ruby-1.9.3-p203) (2012-05-19 00c8c98) (OpenJDK 64-Bit Server VM 1.6.0_20) [linux-amd64-java]
      Errno::ENOENT: No such file or directory - XXX
      _spawn_internal at org/jruby/RubyProcess.java:992
      spawn at file:/PPPPPPP/jruby-1.7.0.preview1/lib/jruby.jar!/jruby/kernel19/process.rb:3
      (root) at -e:1

      % jruby -v -e 'print IO.popen([["/bin/ls", "XXX"]], "r+")

      { |io| io.read }'
      jruby 1.7.0.preview1 (ruby-1.9.3-p203) (2012-05-19 00c8c98) (OpenJDK 64-Bit Server VM 1.6.0_20) [linux-amd64-java]
      TypeError: can't convert Array into String
      popen at org/jruby/RubyIO.java:3813
      (root) at -e:1


      In MRI, all of the above works. (Note that Process.spawn and IO.popen with this style are supported since Ruby 1.9.)

      % ruby187 -v -e 'exec(["/bin/ls", "XXX"])'
      ruby 1.8.7 (2010-08-16 patchlevel 302) [x86_64-linux]
      (result of /bin/ls is displayed)

      % ruby -v -e 'Process.waitpid Process.spawn(["/bin/ls", "XXX"])'
      ruby 1.9.3p253 (2012-07-04) [x86_64-linux]
      (result of /bin/ls is displayed)

      % ruby -v -e 'print IO.popen([["/bin/ls", "XXX"]], "r+") { |io| io.read }

      '
      ruby 1.9.3p253 (2012-07-04) [x86_64-linux]
      (result of /bin/ls is displayed)

      In MRI, when the program is an array containing two String objects, the first element of the array is executed, and the second element is used for the display name.

      This style is used when executing a program with no arguments without invoking the shell. This is useful to avoid potential security problem related with white speces and shell special characters.

      % ruby -v -e 'exec("ls -l")'
      ruby 1.9.3p253 (2012-07-04) [x86_64-linux]
      (result of "ls -l" is displayed)

      % ruby -v -e 'exec(["ls -l", "XXX"])'
      ruby 1.9.3p253 (2012-07-04) [x86_64-linux]
      -e:1:in `exec': No such file or directory - ls -l (Errno::ENOENT)
      from -e:1:in `<main>'

        Activity

        Hide
        Charles Oliver Nutter added a comment -

        JRuby has moved bug tracking to Github, accessible via our Github page at https://github.com/jruby/jruby/issues, or via http://bugs.jruby.org. In addition, this bug has not been updated in over two years.

        We have decided to close down these old JIRA issues.

        If your report is still a problem on current JRuby versions (1.7.18 or master/9.0.0.0), please re-file the bug at http://bugs.jruby.org.

        You can contact us on the JRuby mailing lists, Freenode IRC channel #jruby, or the @jruby Twitter account if you are unsure how to proceed.

        Show
        Charles Oliver Nutter added a comment - JRuby has moved bug tracking to Github, accessible via our Github page at https://github.com/jruby/jruby/issues , or via http://bugs.jruby.org . In addition, this bug has not been updated in over two years. We have decided to close down these old JIRA issues. If your report is still a problem on current JRuby versions (1.7.18 or master/9.0.0.0), please re-file the bug at http://bugs.jruby.org . You can contact us on the JRuby mailing lists, Freenode IRC channel #jruby, or the @jruby Twitter account if you are unsure how to proceed.

          People

          • Assignee:
            Thomas E Enebo
            Reporter:
            Naohisa Goto

            Dates

            • Created:
              Updated:
              Resolved: