2014-07-22 3 views
0

다음 코드를 사용하여 Java에서 bat 파일을 실행하려고했습니다.Java에서 bat 파일을 실행할 수 없습니다.

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

다음과 같은 오류가 발생했습니다.

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 

내 파일은 내가 선언 한 위치에 있습니다. 해결 방법? 사전에

감사

+0

Runtime.getRuntime() 간부 ("cmd를/C를 시작 C : \\ 시험 \\ run.bat를."); http://stackoverflow.com/questions/615948/how-do-i-run-a-batch-file-from-my-java-application –

답변

1

귀하의 시도 할 수 있습니다이

Runtime.getRuntime().exec("cmd /c start run.bat", null, new File("C:\\Test\\")); 
관련 문제