使用java.lang.Process从php代码读取属性

时间:2015-01-20 13:30:24

标签: java php

我正在使用java.lang.Process运行PHP代码,我想从PHP代码返回一个值,所以我可以从Process获取它,我该怎么做?

这是我正在使用的代码:

public void callPhpListener(String handler, String logFile, String messageId) throws Exception {
try {
  LOGGER.info("Calling PHP executore with message id:" + messageId);
  // LOGGER.info("Handler:" + handler + ", logFile:" + logFile + ", message id:" + messageId);
  Process exec = Runtime.getRuntime().exec(
      new String[] {"/bin/bash", "-c",
        "php " + handler + " " + messageId +
          " >> " + logFile + "  2>&1"});
  exec.waitFor();
  int exitValue = exec.exitValue();
  LOGGER.info("exit value is " + exitValue);
  if(exitValue != 0) {
      throw new Exception("Processed with error");
  }
    LOGGER.info("Done processing message with id:" + messageId);
  } catch (Exception e) {
    LOGGER.error(e.getMessage());
    throw new Exception();
  }

}

0 个答案:

没有答案