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: Open Open
    • Priority: Major Major
    • Resolution: Unresolved
    • 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

        There are no comments yet on this issue.

          People

          • Assignee:
            Thomas E Enebo
            Reporter:
            Naohisa Goto
          • Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

            • Created:
              Updated: