Reputation: 2154
I tried to execute a jar file using php's shell_exec(). The pgp file runs on a server.
I researched the problem and tried the following things but no success so far:
The command looks like:
shell_exec("/usr/lib/jvm/java-7-oracle/bin/java -jar PATH_TO_MY_JAR_FILE.jar");
I copy and paste the command into shell and it runs fine.
----------------------------Update-------------------------------------
I made some progress on debugging and want to update the problem a little bit.
I tried to debug using
exec("command from above", $output, $exit_code)
echo $output;
echo $exit_code;
and done some fixing and now I am sure the php script is executed but it's not doing what I want.
So the jar file's purpose is to create a json file in the system. I specify the absolute path for this json.
Now, after I run the php file, the $output shows
Array ( [0] => {"balance":"c","num":"b","is_vip":true,"name":"a"} )
This is the same output when I run the command in shell
$exit_code's value is 10
But I can't find the json file in the system.
Upvotes: 1
Views: 891
Reputation: 1318
Did you check if the php safe mode is enabled on the server? The documentation of http://php.net/manual/en/function.shell-exec.php says:
Note: This function is disabled when PHP is running in safe mode.
Nevertheless: the documentation also says, that the safe_mode is deprecated since PHP5.3 so hopefully, this does not affect your server.
Additionally you should check if the php user is allowed to execute +x
the java binary.
Upvotes: 1