benjisail
benjisail

Reputation: 1666

Detect if java is installed on the web server from php

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

Answers (2)

Okonomiyaki3000
Okonomiyaki3000

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

prodigitalson
prodigitalson

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

Related Questions