Runtime.exec() not working on tomcat.
I have a problem in running a command from java web application. I used runtime.exec(). It's working fine at eclipse. But not working at all after deployed on tomcat. I think that runtime.exec() not working at all. Any idea?
I written at server side. I want to create a windows schedule task from runtime. Here is my code.
String l_Time = pData.getTimeStamp();
ProcessBuilder builder = new ProcessBuilder("cmd", "/c", "start SchTasks /Create " +
"/SC WEEKLY /D MON,TUE,WED,THU,FRI,SAT,SUN /TN \"TaskName\"" +
" /TR \"D:/Test/Test.bat\" /ST 09:00\"");
builder.redirectErrorStream(true);
Process p = builder.start();
BufferedReader r = new BufferedReader(new InputStreamReader(p.getInputStream()));
String line;
while (true) {
line = r.readLine();
if (line == null) { break; }
System.out.println(line);
}
p.waitFor();
int exitVal = p.exitValue();
System.out.println("Process exitValue: " + exitVal);
if you are trying to execute in Runtime.exec() then it will not work in client side
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With