0

I have a jar file named MyJar.jar and it accepts 4 parameters. I need to execute this jar file using a php script. The php file and the jar file are located in the same directory.
When I try to use the system function simply nothing happens, no output no nothing. This is also the case for other functions such as exec, passthru and etc.

This is how I try to run the file.

system('java -jar ./MyJar.jar arg1 arg2 arg3 arg4');
// and also
system('./MyJar.jar arg1 arg2 arg3 arg4');
// and also
exec('./MyJar.jar arg1 arg2 arg3 arg4',$output);
print_r($output);
// nothing works

UPDATE: Thank for your answers. But I've tried everything. I tried using absolute paths to my jar file. I've tried every possible combination of command relay functions with absolute and relative paths. I tried changing directory using chdir. pwd shows that I'm in the right path. I don't know what to do anymore.

UPDATE 2: I just found out something odd. When I use system call and specify a return value, the number 6 is return. If I understand correctly 6 means the proccess has been aborted or something. I wonder what that means?

UPDATE 3: After checking the error logs, the following error was generated. Can anyone help me with it?

dl failure on line 696Error: failed /usr/lib/jvm/java-6-openjdk-i386/jre/lib/i386/server/libjvm.so, because /opt/lampp/lib/libgcc_s.so.1: version `GCC_4.2.0' not found (required by /usr/lib/i386-linux-gnu/libstdc++.so.6)

3
  • Is it possible that the problem is with the jar file? Can you run it manually and see if it operates correctly?
    – Lix
    Aug 24, 2012 at 7:14
  • Nope. The jar file is ok. It runs flawlessly from the command line.
    – 2hamed
    Aug 24, 2012 at 7:15
  • You might need the full path to java specified, I'm not sure if system() or exec() checks the PATH variable
    – Darkzaelus
    Aug 24, 2012 at 7:18

4 Answers 4

1

Check your apache error log, maybe the execution is being blocked and have PHP set to hide errors.

Also, try (just as an experiment) using full paths - both far java and the .jar file.

0

After checking your log, you may find your PHP.ini is blocking commands with something like:

disable_functions =exec,passthru,shell_exec,system,proc_open,popen,curl_exec,curl_multi_exec,parse_ini_file,show_source 

Remove 'system' and 'exec' to allow these functions in PHP.

1
  • The functions are all active. Other shell commands such as ls run w/out any problem.
    – 2hamed
    Aug 24, 2012 at 7:25
0

Do you call your php script from another script with include or require?

Make a system call to pwd to ensure the correct working path. It should be the same as the path to the jar file

system('pwd');

Other ways you could fail: The apache/php user is not allowed to run the jar file. Try to set a file permission of 0777 (-rwxrwxrwx) or 0666 (-rw-rw-rw) to the jar file and see, if it makes any difference.

Is the file really called MyJar.jar? Is the case correct? Linux is case sensitive. Are there space characters in the file name, then you should quote/escape the filename.

The path to the java executable may not be found. Try system('which java') and then prepend the call to in your system call with the path. Also try an absolute path to the jar file.


update Try to start a Hello World Java Programm from within PHP to test, if it really can be run. So you know the problem is not with the Java Programm itself.

0
0

Please look into your domain configuration whether safe mode is on or not for your domain. That will block the exec function

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.