build and execute a bash script from a java script with spaces-Collection of common programming errors

i am creating a java application which is will be GUI for a bash script..

The application will be used browse the script location and enter 2 other parameters..

and build and execute the command..

so the execute part will be like this:

Runtime rt = Runtime.getRuntime();
Process pr = rt.exec(scriptPath + parameter1 + parameter2);

if the command work if the script’s location doesn’t has spaces in it..

but when it has spaces it stops when it reach the first space.. and it gives me “java.io.IOException:” exeption..that the file is not found..

i have tried replacing the spaces with backspace and space..

scriptPath.replace(" ", "\\ ")

i also tried adding quotes before and after the path

"\"" + scriptPath + "\""

and i have tried them both together..

"\"" + scriptPath.replace(" ", "\\ ") + "\""

but none of them had worked..

any help will be appreciated..

regards..