Replace space characters in paths with what?
I start bash from Java app and I have in my path for command which executes inside bash spa开发者_Python百科ces ( example cd /Documents and Settings/test ), I run command with Process Builder but it doesn't work when path have spaces. I try to replace spaces with %20 but not help. What to do ?
You can either encapsulate the full path in quotion marks like this:
String quoted = "\"" + pathString + "\"";
or, as you use bash, escape the spaces:
String escaped = pathString.replace(" ", "\\ ");
Both should work as an argument for your cd
command.
encapsulate the whole path between quotations.
cd "/Documents and Settings/test"
Using %20 here is nonsense, it's no URL. Use String[] or List[] instead of String and then you can leave the spaces as they are, there's no more cmd line args splitting there.
So you could use
"cd", "/Documents and Settings/test"
however, this make no sense as a shell command. You can't change the working dir of Java this way, as you're starting a new process. You may want to write a shell script (batch file) and invoke it from Java.
You need to run a command which works from the bash prompt. e.g. cd /Document and Settings/ won't. Try cd C:Documents\ and\ Settings
which does.
NOTE: bash requires you use a C: at the start to access this folder. Using just / at the start will give you cygwin's a virtual root.
精彩评论