Here is my PHP code:
<?php
exec('java -jar ~/src/epubcheck-*/epubcheck-*.jar -out /var/www/epubcheck-outputs/output.xml /var/www/AChristmasCarol.epub');
When I try the command in the terminal it works… But in PHP it does not.
Also I don’t even get the java version. But I do get to see the “hey…” so some commands do work, others don’t.
I am using NGiNX has my server.
The documentation for exec explains that only the last line of the output is returned by exec, so you need to use a parameter to capture the full output.
java -versionsends its output toSTDERR, notSTDOUT, so you need to redirectSTDERRtoSTDOUTif you want to capture the output of that command with PHP.However, this shouldn’t be necessary when you’re running an ordinary java program.
If this still doesn’t work, see my comment on Ibu’s answer
Edit: Actual answer, from question comments:
~/src/epubcheck-*/epubcheck-*.jarcould be a problem here –~is a shortcut for the home directory of the current user – so when you run the command yourself, it means/home/username/src/..., but when you run it as your webserver’s user, it means an entirely different path. Try changing that to the full path of the jar files you want to execute.