无法使用java在cent os中执行终端命令

时间:2015-06-29 10:50:31

标签: java jersey tomcat8

当我尝试在java代码下运行时,获得异常

Java代码: -

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;

例外: -

      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)

0 个答案:

没有答案