tags:

views:

60

answers:

1

I have made a custom java program to output a license and am trying 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 out the $command using

echo $command;

and then ran that command directly in the linux terminal and the xml output was correct.

I am using

System.out.println() 

in the java app to print all the xml output. I tried something simple like

shell_exec('ls -l') ;

and sure enough if worked.

What might I be doing wrong?

A: 

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

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

The command which java will return the full path to the java executable...

ircmaxell
$java = `which java`; echo $java; produced nothing, however $java = `ls -l`; echo $java; worked
jax
`which ls` produced /bin/ls so for some reason php can't locate java even with the which command
jax
I used the full path /usr/java/jdk1.6.0/bin/java in the php command instead of java and it worked.
jax