Uploaded image for project: 'Groovy'
  1. Groovy
  2. GROOVY-427

Can't execute a command line where arguments have spaces in them

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Major
    • Resolution: Fixed
    • None
    • 1.0-JSR-1
    • groovy-jdk
    • None
    • latest CVS head, mac os X 10.3.2, java 1.4.2

    Description

      I need to execute a process with arguments that have spaces in them. I have tried every variation I could think of to escape the space, to no avail. Here are the variations I tried:

      cmd = ["ls /Users/john/Library/Application Support",
      "ls /Users/john/Library/Application\ Support",
      "ls /Users/john/Library/Application
      Support",
      "ls '/Users/john/Library/Application Support'",
      'ls "/Users/john/Library/Application Support"']

      cmd.each {
      print "${it}: "
      p = it.execute()
      p.waitFor()
      println "returned: ${p.exitValue()} output: ${p.text} stderr: ${p.err}"
      }

      Here is the output I got from this:

      ls /Users/john/Library/Application Support: returned: 0 output: stderr: ls: /Users/john/Library/Application: No such file or directory
      ls: Support: No such file or directory

      ls /Users/john/Library/Application Support: returned: 0 output: stderr: ls: /Users/john/Library/Application: No such file or directory
      ls: Support: No such file or directory

      ls /Users/john/Library/Application\ Support: returned: 0 output: stderr: ls: /Users/john/Library/Application\: No such file or directory
      ls: Support: No such file or directory

      ls /Users/john/Library/Application\ Support: returned: 0 output: stderr: ls: /Users/john/Library/Application\: No such file or directory
      ls: Support: No such file or directory

      ls '/Users/john/Library/Application Support': returned: 0 output: stderr: ls: '/Users/john/Library/Application: No such file or directory
      ls: Support': No such file or directory

      ls "/Users/john/Library/Application Support": returned: 0 output: stderr: ls: "/Users/john/Library/Application: No such file or directory
      ls: Support": No such file or directory

      I would suggest we add an execute() method to Object[] and use the exec() version of Runtime that takes an array of arguments. My current workaround is to use the Runtime.exec() method directly and not use the execute() on String.

      Attachments

        Activity

          People

            blackdrag Jochen Theodorou
            johnstump John Stump
            Votes:
            1 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: