1

While i am trying to run below java code ,getting an exception

Java code :-

String status;
        Process proc = Runtime.getRuntime().exec("sudo\t/etc/init.d/idns status");
        BufferedReader stdInput = new BufferedReader(new InputStreamReader(proc.getInputStream()));
        status = stdInput.readLine();
    if (status.equals("gtd is stopped")) {
            Runtime.getRuntime().exec("sudo\t/etc/init.d/idns   start");
            logger.info("IDNS service started...");
            status="IDNS Service Started.";
        } else {
            Runtime.getRuntime().exec("sudo\t/etc/init.d/idns   restart");
            logger.info("IDNS service restarted...");
            status="IDNS Service Restarted.";
        }
        return status;

Exception :-

      29-Jun-2015 03:18:54.511 SEVERE [http-nio-8080-exec-381]        org.apache.catalina.core.StandardWrapperValve.invoke Servlet.service() for        servlet [idnsRulesServlet] in context with path [] threw exception
      java.lang.NullPointerException
at    org.idnsrules.engine.activities.JSONTOyaml.jsonToYaml(JSONTOyaml.java:69)
at      org.idnsrules.engine.dao.IdnsRulesDAO.restartIdnsService(IdnsRulesDAO.java:258)
Murugesan Era
  • 335
  • 1
  • 17
  • 1
    Try Like This. [http://stackoverflow.com/questions/18708087/how-to-execute-bash-command-with-sudo-privileges-in-java][1] – Ajith John Jun 29 '15 at 10:56
  • @ Ajith John this exception i am getting. javax.servlet.ServletException: java.io.IOException: Cannot run program "/etc/init.d/idns status": error=2, No such file or directory com.sun.jersey.spi.container.servlet.WebComponent.service(WebComponent.java:420) – Murugesan Era Jun 29 '15 at 11:15

0 Answers0