duanjiancong4860 2016-04-06 07:48
浏览 37

我无法从php调用java

The system variable 'Path' contains C:\Program Files\Java\jre7\bin\ It seems like, I cant even access java from PHP. The system is Windows Server 2012. From the cmd terminal, java works fine.

When I call the java command via exec from php like this:

exec("java -version", $string);
preg_match("/java version \"(.*)\..*.*\"/", $string[0], $matches);
$java_version = $matches[1];

$java_version is null.

Any ideas?


I suspect, it has something to do with access rights on Windows, might that be?

  • 写回答

1条回答 默认 最新

  • doudong7256 2016-04-06 07:59
    关注

    When you call java -version the output is written to stderr. So write

    exec("java -version 2>&1", $string);
    

    to capture stderr output.

    评论

报告相同问题?