Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

java runtime.exec() not working on tomcat

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);
like image 401
Hlaing Myo Avatar asked Dec 05 '25 13:12

Hlaing Myo


1 Answers

if you are trying to execute in Runtime.exec() then it will not work in client side

like image 131
SpringLearner Avatar answered Dec 08 '25 06:12

SpringLearner



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!