Reputation: 1666
Is it possible to detect from a php script if java is installed on the server (if I can run an exec() command with java)?
Thanks,
Benjamin
Upvotes: 4
Views: 2574
Reputation: 3696
I've used this:
$result = exec('command -v java >/dev/null && echo "yes" || echo "no"');
$result
should be yes
if the java command exists or no
if it doesn't. You need a different command if you're running on Windows. Maybe something like:
$result = exec('java -version > NUL && echo yes || echo no');
Upvotes: 2
Reputation: 60413
Well if you can run exec
you should be able to use the cli detection of your choice like which java
, locate java
etc.. Im sure there are tons of methods to do this (the two i presented not necessarily the best).
Upvotes: 2