views:

47

answers:

1

I've got a jar file I created that can generate a PDF file. I've called it from the command line like this -

java -jar project.jar 'Author, An---A Title'

This works fine but when I call the same jar file from a PHP file with the following code it creates a file with the correct name but its empty and has zero bytes.

<?php
    echo exec("java -jar project.jar 'Author, An---A Title'");
?>

I'm sure this is a problem not with the jar (since it works from the commandline) and I'm almost sure its not from the PHP file (since it created the empty file, so it must have been read), so I think the problem might be with permissions on the directory? I'm using linux and the PHP is running through XAMMP which is in the OPT directory. Any ideas?

Thanks in advance.

A: 

I am not sure if you have control over the Java source code but at least the symptoms indicate that it is not calling close() on the OutputStream or Writer of the file in question.


Update: try shell_exec() instead to see what the result says. Probably it threw some exception halfway which got written to the stderr which you completely missed in the PHP code. The exec() namely only captures the stdout.

$result = shell_exec("java -jar project.jar 'Author, An---A Title'");
if ($result) {
    echo nl2br($result);
} else {
    echo "shell_exec() failed";
}
BalusC
That doesn't seem to have worked. I don't think its a coding problem since I don't have a problem when calling it from the commandline.
usertest
See answer update. Probably you can find more interesting information in the stderr.
BalusC
Hi, I just tried you update code with no luck. Now I'm sure its something to do with permissions. I tried manually creating a text file, which works. Then when I try to save something I can't. I can save after I chmod 777 everything in the directory. I have to do this after each file I manually create. How can I make sure all files in a specific directory are always writeable? Thanks.
usertest