but when i run this it will take only till "c:\\my and says your path is not correct
i want to figure out the space between my and path so that i can have the full path .. please help me out
this is what i am passing
after executing this it's throw error d:\program directory couldn't found
fred rosenberger wrote:the problem is (i believe) when the OS gets your string, it breaks your string up into tokens based on the space. You need to tell it that the entire string is the path, and to not break it up. To do that, you need to surround it in quotes. To put quote characters inside a string in java, you need to escape them - which is what Wouter posted above.
The damage is done before the command ever gets to the OS. Runtime has overloaded methods public Process exec(String command, String envp, File dir), public Process exec(String command, String envp) and public Process exec(String command). On the surface, these would seem to be ideal for just creating a simple command line without having to go to the bother of constructing an array BUT do not be deceived. The second two methods delegate to the first (with appropriate values of unused parameters) and Looking at the source code for Process exec(String command, String envp, File dir) one sees :-
Ouch! All this does is to split the command String at white spaces and create an array of the fragments which is then passed to the overloaded exec() method that takes the array as argument. What is worse, multiple spaces are in effect reduced to single spaces and my experiments indicates that Linux and Windows behave differently.
My advice - don't even think about using the single String version of exec() (or ProcessBuilder) because it will at some point jump up and bite you.
What the OP needs to do is something along the lines of -
Note the absence of the 'start'; this is rarely needed.