I want to call a java program and fetch it's output in stdout. I followed the suggestions in stackoverflow. But it doesn't work.
I have add the class file to my CLASSPATH. And I can execute the command in cmd correctly as follows:

In my PHP file I call this program by
exec("java Hello", $output);
print_r($output);
It yields nothing but:
Array()
What is the problem? How can I fix this?
ps: Hello is a demo program, actually the program I want to call is much more complicated which might take 2 or more seconds in my machine(i5 4G).
passthru()gives back (instead ofexec()).exec()might be selective sometimes to catch only returned values rather than printed content. Useescapeshellarg()to secure your script against hacks.1.main()function in your JAVA program returns 1 (return 0 = no errors, 1 = somethings wrong ;)) it means there was an error. It might have something to do that PHP's commandline doesn't fetch your JAVA the same way as you do incmd. Both are of course different settings-wise. Likecakilanswered it might work to loop on the Array() you got back, as echo/print in PHP won't show the inners of an Array by default, like you might be used to in other languages.passthruactually gives nothing intead of1, I said1because I mistakenly set the class. Anyway, thank you. And if this won't work anyway, I can alternatively try to wrap this in jsp file or some other server-script language. I just want to make it on-line such that users can access the processed data yield by the java program. The worst case is that I have to translate the java program to PHP or other server-script language...return 0;in your JAVA class, at least to test ifpassthru()is not always giving back 1. It should read RAW-input, so it's really something with calling JAVA from the PHP script. Maybe (to test) try execute JAVA from it's absolute path too. The more you test, the more you will mostly get to know :)