-1

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
cfrick
  • 35,203
  • 6
  • 56
  • 68
arjun arjun
  • 28
  • 1
  • 8

2 Answers2

1

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.

cfrick
  • 35,203
  • 6
  • 56
  • 68
  • groovy: JAVA_HOME not set and cannot find javac to deduce location, please set JAVA_HOME. – arjun arjun Mar 27 '15 at 14:03
  • well, it pretty much says it all: set your java environment up properly. if you can not do this, then spawn the process with that env var set. – cfrick Mar 27 '15 at 14:07
0

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;

Opal
  • 81,889
  • 28
  • 189
  • 210
arjun arjun
  • 28
  • 1
  • 8