我无法从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?

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

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

to capture stderr output.