i want to run a java code after the php script takes a input from the browser and then pass on the answer back on the server can someone help me with this
3 Answers
You can use PHP's exec function.
Example:
$result = exec("java -jar yourjava.jar");
Java program's last standard output line will be stored in $result.
If you need capturing standard output:
$out = array();
exec = ("java -jar yourjava.jar", $out);
print_r($out);
2 Comments
Edoardo Pirovano
Actually, according to the documentation the return value is the last line that the program outputted, not the exit status. If I am not mistaken, if you need to get the exit status you should provide a variable that it will go into as the third parameter.
Pablo Santa Cruz
@EdoDodo: awesome. Will fix that. Thanks!
You'll probably want something like this:
exec("/path/to/program $argumentToPass");
2 Comments
sudhanshu
i also wanted to have inputs send to my program how could i do that
Edoardo Pirovano
In my code example, the variable $argumentToPass will be sent to the program as its only argument. If you explain in more detail the inputs you want to pass, I can give you a better example.
maybe this is what you're looking for (the question is very unspecific) - otherwise, if you just want to execute something (regardless of wether it's a java-programm or something else) use exec() like the others said.
1 Comment
oezi
thanks for the hint KingCrunch. it's not said wich php-version is used (and unfortunately there are still a lot of people out there using php4) - and on the liked site, there's a commet with some solutions for php5.