Karthik Karthik - 2 years ago 154
Bash Question

Executing shell script from java code and check if execution has passed

I am using below command to execute a shell script from java. I also need to check if script execution is successful without any errors. Is there any possible method to do this? Please advise.

ProcessBuilder pb = new ProcessBuilder("test.sh", arg1, arg2);
Process p = pb.start();

Answer Source

You need to check if the process terminated which you can do with Process.waitFor() which blocks until the process completed. The return value of this call is the return code of the system command you invoked.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download