Execute .bat file from java? -
i come previous problem executing .bat file java program.
when execute java code, don't understand why it's looking .bat file in project directory of eclipse.
i declare path : "cmd.exe", "/c", "start", "c:\\file\\batfile.bat"
if explain me clearly, please. thank much!
i use win xp , eclipse helios.
here code:
string cmd; try { string[] command = { "cmd.exe", "/c", "start", "c:\\file\\batfile.bat" }; runtime r = runtime.getruntime(); process p = r.exec(command); p.waitfor(); } catch (exception e) { system.out.println("execution error");}
the process cmd.exe (picked path environment variable) created current working directory same in parent process (eclipse.exe = java). c:\eclipse or workspace dir.
if cant find file (c:\file\batfile.bat) tries current working dir. if run code using run java try change working directory there. make sure bat file exist.
Comments
Post a Comment