0

I have code which has to read a bat file and run it. But path contains Space how we can read space in java in file path. Below is the code

   String cmd5 = "cmd /c start E://Test 1.4.3/start.bat";
    Process p5 = Runtime.getRuntime().exec(cmd5);
geisterfurz007
  • 5,292
  • 5
  • 33
  • 54

2 Answers2

1

Try

String cmd5 = "cmd /c \"E:\\Test 1.4.3\\start.bat\""

see: How do I deal with quote characters when using cmd.exe

Community
  • 1
  • 1
Mr. T
  • 65
  • 1
  • 8
0

You can try quotes around it

String cmd5 = "cmd.exe /c start \"E:/Test 1.4.3/start.bat\"";
Process p5 = Runtime.getRuntime().exec(cmd5);

or a string array

String[] cmd5s = { "cmd.exe", "/c", "start", "E:/Test 1.4.3/start.bat" };
Process p5 = Runtime.getRuntime().exec(cmd5s);

For the rest ProcessBuilder is nicer in usage than Runtime.

Joop Eggen
  • 107,315
  • 7
  • 83
  • 138