I'm trying to execute a command through shell_exec
in php. But I'm getting an error.
My code :
shell_exec('groovy log_analyser1.groovy').
But I'm getting this error :
sh: groovy: command not found
I'm trying to execute a command through shell_exec
in php. But I'm getting an error.
My code :
shell_exec('groovy log_analyser1.groovy').
But I'm getting this error :
sh: groovy: command not found
Put groovy installation somewhere sane (/usr/local
or /opt
or whatever your ops team allows you) and then call groovy with the absolute path.
Since you have currently installed in in your root
users ~
, other users (like the user your php/httpd runs as) don't have access to it (for good reasons).
Even if you would use the same user as your php/httpd and use GVM there you will have a hard time to make this work properly, since GVM relies on some scripts to run. So just copy from your GVM files (~/.gvm/groovy/<version>
) where it's easy for all users to access it.
Finally got the output. I have moved the groovy directory from /root to /usr/share/. Then gave the groovy path in my php file. Now its working fine. To set java environmental variable.
I have set this putenv("JAVA_HOME=/usr/share/java/jdk1.7.0_03/");
$result = shell_exec('/usr/share/groovy/2.4.3/bin/groovy log_analyser1.groovy');
Thanks Cfrick for the help. echo $result;