I have an application I'm trying to run through a Runtime.exec() call.
Since some of the arguments have spaces, how can I properly escape the arguments such that it works both in Linux and Windows? I know with Windows, you typically use double quotes around a string with spaces, while linux uses a slash.
With the spaces, I'd expect the program I'm running (Windows' xcopy for now) to return almost immediately and indicate the number of parameters is wrong. But, the waitFor() call hangs.
String[] commandArray = new String[3];
commandArray[0] = applicationPath;
commandArray[1] = someFileWhichMayHaveSpaces;
commandArray[2] = anotherFileWhichMayHaveSpaces;
Process appProcess = Runtime.getRuntime().exec(commandArray);
int returnCode = appProcess.waitFor();
Looks like there isn't an issue at all with spaces in the args, at least testing in teh Windows environment. The issue was that xcopy was prompting /halting for a response to a question if the copy source was a file or directory. I assumed it was choking on the spaces, but apparenlty it was not. I was able to use the code I have in the question as is, and didn't have to use ProcessBuilder.