tags:

views:

73

answers:

1

Hi,

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

+2  A: 

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).

prodigitalson
`locate java` could return false positives if there are files on the f/s named "javascript" or similar. `which` is a better choice, but it depends on the java binary to be in the system path. I'm not sure either of these are great though.
AJ
@AJ: +1 - i forget the caveats with those commands as i generally dont use them in the context of a script to ensure existence of something. But my point is if he has access to `exec` there are all kinds potential avenues to take here, these being two possibilities. Do you have any recommendations?
prodigitalson
Which one is less resource consuming if you have access to exec?
benjisail
what about "java -version" ?
zmf
@zmf: Well that would imply that `java` is on the path of the user calling php. Which it may or may not be. In order to get around that youd need to know the full path to `java` which would also mean that you already know java exists.
prodigitalson
@prodigitalson ah makes sense, ty
zmf