Reputation: 1582
I recently updated my Java version to JDK7u21. In the release notes of update 21, it is clearly mentioned about issue using Runtime.exec.
I therefore want to change my code to use ProcessBuilder. I am trying to execute a command with spaces in it. But even if using ProcessBuilder for this, I land up in C:\Users\Parag.Joshi\Documents and not the exact directory.
Below is my code:
ProcessBuilder p = new ProcessBuilder("cmd", "/c", "explorer ", "C:\Local Disk D\My Tutorial");
p.start();
I had a look at Java execute a command with a space in the pathname but didn't get a clue.
Upvotes: 3
Views: 4295
Reputation: 17595
I just tested it on my local machine.
the behaviour is caused because of the space after "explorer "
. remove that space and it will work. Also you need to quote the \
.
ProcessBuilder p = new ProcessBuilder("cmd", "/c", "explorer",
"C:\\Local Disk D\\My Tutorial");
Upvotes: 5