Hello all: Running into some difficulty here. I'm trying to call a java .jar file through PHP's "exec()" command-line execution process - Red Hat Linux environment. I'm successfully setting the working directory up front and the exec function returns no errors, but the java interpreter never actually gets fired off. Here's a sample code of what I'm trying to do: <?php $webdir = getcwd(); // Get main web root directory (should be "/var/www/html") $sourcedir = "$webdir/java"; // We want to start in the java directory chdir ($sourcedir); // Change to new java directory $execparam = "java -jar JavaFile.jar &"; // Call the jar file and run in the background exec ($execparam, $output, $return); // Run it foreach ($output as $line) { print "$line<BR>"; } print "$return<BR>"; ?> PHP: That's it. Nothing is being stored in "$output" and "$return" returns "0", which I understand to be a successful run, yet no Java process gets started. I've also tried the "shell_exec()" and "system()" functions with similar (no) results. Anything stand out to anyone on this? Any assistance appreciated.
Update: When removing the "&" command to run this thing in the background, a generic error code of "127" is returned, rather than "0". Additionally, when I tried using the "popen()" function, I need to specify the location of the java interpreter, but when I do, I get the following error which gives me a little more information: "sh: /usr/bin/java: Permission denied". I have since added the "apache" user to the "root" group, but that hasn't changed anything. Is this really a permissions problem or a path problem? Very confused now...
Because it has no interface. It's was strictly designed to be a command-line thing and it was decided to put a PHP front end on it later on. I've used command line executions before, but for some reason it's not behaving with Java. I ran into this situation on Windows, where I had to go into the actual Apache service preferences and click on the "Allow service to interact with desktop" checkbox, allowing PHP code to initiate a Windows client app. I get the feeling this is a similar issue, but in Linux, like there is some setting that will allow PHP to make remote command-line calls to Java.
This might help as well. Not a solution with the posters original code: http://us3.php.net/manual/en/java.examples.php