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:
- I specify the full java path in the command
- I make sure shell_exec()/exec() function is not disabled on the server, the server is not run on safe mode
- I change the permission of the jar file to be executable
- I also try using exec()
- I test command like exec("ls", $out), and it works fine
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.