Runtime.exec on argument containing multiple spaces

Ok, this is not simply an update but also an answer so I’m filing it as one. According to all information I could find, the following should theoretically do it:

String[] cmd = {“explorer.exe”, “/select,\”C:\New”, “”, “”, “”, “”, “”, “”, “Folder\file.txt\””};

The multiple spaces have been broken into empty strings and the array version of exec is used.
Using the above array, I debugged the loop in lines 50-75 of java.lang.ProcessImpl where a string is finally constructed. The resulting string was:

explorer.exe /select,”C:\New       Folder\file.txt”

This is what is passed as the 1st argument to ProcessImpl’s native create method (line 118 same class), which as it seems fails to run properly this command.

So I guess it all ends here… sadly.

Thnx prunge for pointing out the java bug.
Thnx everyone for their time and interest!

Leave a Comment