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

1

1 Answer 1

1

Your can try this

  Runtime.getRuntime().exec("cmd /c start run.bat", null, new File("C:\\Test\\"));
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.