Executing a file from a location containing spaces.
OK my problem is I'm not sure how I'm supposed to navigate to a file location that contains space because this code stops reading the file location at the first space.
Code:
Runtime run = Runtime.getRuntime();
try {
Process pp=run.exec("C:\\Riot Games\\League of Legends");
}catch (Exception e) {
e.printStackTrace();
System.out.println(e.getMessage());
}
I get this error
Code:
java.io.IOException: Cannot run program "C:\Riot": CreateProcess error=2, The system cannot find the file specified
at java.lang.ProcessBuilder.start(Unknown Source)
at LoLStarter$startButtonListener.startLoad(LoLStarter.java:151)
at LoLStarter$startButtonListener.actionPerformed(LoLStarter.java:140)
I feel like this is really simple but I cannot think of what this would be.
Re: Executing a file from a location containing spaces.
Try one of the other exec( ... ) methods (one that doesn't break up your String).
kind regards,
Jos
Re: Executing a file from a location containing spaces.
I'm looking in the exec api and the only thing I think I can use is the getLocalizedInputStream(InputStream in). I don't know how I would stop my string from getting broken up using .exec();.
Re: Executing a file from a location containing spaces.
You didn't look good enough; the exec(String[] cmdarray) version does what you want (it doesn't break up a single String).
kind regards,
Jos
Re: Executing a file from a location containing spaces.
Oh I misunderstood what you meant then. In the actual code I am passing it a String Array but it wasn't working. I found an example on how to use the exec(String[] cmdarray) version and its now working perfectly.
Thanks JosAH for tolerating my derp moment.