0

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 3

2

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);
Sign up to request clarification or add additional context in comments.

2 Comments

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.
@EdoDodo: awesome. Will fix that. Thanks!
0

You'll probably want something like this:

exec("/path/to/program $argumentToPass");

2 Comments

i also wanted to have inputs send to my program how could i do that
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.
0

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

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.