I would like to use Runtime.exec() to initiate another process in a directory with spaces. (It sounds stupid but I really want to satisfy my curiosity)
Details of the problem(simplified version) I have a myprogram.exe locates in C:/Program Files/MyProgram.
What I observe: 1). when I call Runtime.exec("C://Program Files//MyProgram//myprogram.exe"), IOException indicates: can't find file C:/Program, with error code = 2. I think it must a result of the space
2). I tried: Runtime.exec("/"C://Program Files//MyProgram//myprogram.exe/""), IOException indicates: can't find the file: "C:/Program Files/MyProgram/myprogram.exe"
3). I learnt my lesson and try an overloaded version of Runtime.exec(): File dir = new File("C://Program Files//MyProgram//"); And run: Runtime.exec("myprogram.exe", null, dir), and it says: can't find file myprogram.exe in C:/Program Files/MyProgram/
4). I tried 1), instead of "Program Files", I rename it to Program_Files, everything works
I know I can also use ProcessBuilder to do similar thing, but I can't let it go in my heart...(Maybe it's my weakness). Can anyone tell me why 2) and 3) does not work?
Thanks.