0

I tried to run a bat file in Java using the following code.

Runtime.getRuntime().exec("run.bat", null, new File("C:\\test\\"));

I got the following error.

java.io.IOException: Cannot run program "run.bat" (in directory "C:\test"): CreateProcess error=2, The system cannot find the file specified
at java.lang.ProcessBuilder.start(ProcessBuilder.java:1041)
at java.lang.Runtime.exec(Runtime.java:617)
at java.lang.Runtime.exec(Runtime.java:450)
at stl_generator.Program.runCommandScript(Program.java:102)
at stl_generator.Program.createFile(Program.java:20)
at stl_generator.Program.main(Program.java:112)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:606)
at com.intellij.rt.execution.application.AppMain.main(AppMain.java:134)
Caused by: java.io.IOException: CreateProcess error=2, The system cannot find the file specified
at java.lang.ProcessImpl.create(Native Method)
at java.lang.ProcessImpl.<init>(ProcessImpl.java:385)
at java.lang.ProcessImpl.start(ProcessImpl.java:136)
at java.lang.ProcessBuilder.start(ProcessBuilder.java:1022)
... 10 more

My file is exist in the location that I've declared. How to fix this?

Thanks in Advance

hump
  • 53
  • 10
  • Runtime.getRuntime().exec("cmd /c start C:\\test\\run.bat"); http://stackoverflow.com/questions/615948/how-do-i-run-a-batch-file-from-my-java-application – Ungapps Jul 22 '14 at 04:40

1 Answers1

1

Your can try this

  Runtime.getRuntime().exec("cmd /c start run.bat", null, new File("C:\\Test\\"));
Tej Kiran
  • 2,218
  • 5
  • 21
  • 42