Shell_exec () php command not working for my custom java application

I created a custom java program to display the license and try to run it in php.

$deviceid="12345";
$command_app = 'java -jar /home/myname/secure/mycommand.jar ';
$privateKey = 'QEFAASCAmEwggJdAgE';
$command_app_args = "\"$privateKey\" deviceid=$deviceid";
$command=$command_app.$command_app_args;
$license = shell_exec($command);

The problem is that $ license is empty every time, I tried to print the $ command using

echo $command;

and then executed this command directly in the linux terminal, and the xml output was correct.

I use

System.out.println() 

in a java application to print all xml output. I tried something simple like

shell_exec('ls -l') ;

and of course if it works.

What can i do wrong?

+1
source share
1 answer

My first instinct is that the java command is not in the PHP shell path. Try something like this:

$command_app = '`which java` -jar /home/myname/secure/mycommand.jar ';

which java java...

+2

Source: https://habr.com/ru/post/1749600/


All Articles