0

I have PHP that I am running with ajax. What I want to happen is the php executes a java program returns the output of said java program. Right now in my PHP file, as a test I am trying

exec("java -version", $output);
print_r($output);

However, this just prints to the console

Array
(
)

Also, when I add in my actual java program, it is outputting using System.out.println() if that makes a difference as to how it is read by PHP.

1 Answer 1

1

As it states in http://php.net/manual/ru/function.shell-exec.php, you should:

$output = shell_exec('java -version');
print_r($output);
Sign up to request clarification or add additional context in comments.

9 Comments

That just outputs an empty line.
Ok, try this: print_r(shell_exec('echo 111')); What would it output ?
@CameronK , ok, now run "java -version" in terminal without any additional environment changes. Just open new terminal window and run this command. What would it output?
java version "1.8.0_144" Java(TM) SE Runtime Environment (build 1.8.0_144-b01) Java HotSpot(TM) 64-Bit Server VM (build 25.144-b01, mixed mode)
Did you run php code through php-cli, or through some kind of web server (apache, phpfpm) ?
|

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.