Details
-
Bug
-
Status: Closed
-
Major
-
Resolution: Fixed
-
None
-
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.