-1

I am using macbook-pro, and i am executing this php script using apache server, but i am not getting the output of exec() function. It is not even showing any error. Can anyone tell me how to get the output. Thanks in advance.

<html>
<head>
<title>Online PHP Script Execution</title>
</head>
<body>
<?php
   echo "<h1>Hello, PHP!</h1>";
   echo exec('java -version');
?>
</body>
</html>
3
  • 3
    You sure you do not get the expected return from exec()? This sounds a little like you did not read the functions documentation. It does not return the output of the command you execute. Commented Feb 7, 2014 at 12:02
  • 1
    see stackoverflow.com/questions/278868/calling-java-from-php-exec Commented Feb 7, 2014 at 12:03
  • yeah, i have read the documentation and exec() returns the last line of the output, the above script is working on online php compiler and it is giving the java version as output. but it is not working on my computer neither it is giving any error. Commented Feb 7, 2014 at 12:09

1 Answer 1

0
<html>
<head>
<title>Online PHP Script Execution</title>
</head>
<body>
<?php
   echo exec("java -version");
?>
</body>
</html>

output

java version "1.7.0_45" OpenJDK Runtime Environment (rhel-2.4.3.3.el6-x86_64 u45-b15) OpenJDK 64-Bit Server VM (build 24.45-b08, mixed mode)

You can copy and paste the code here ans you'll get the output. Click Here

Sign up to request clarification or add additional context in comments.

2 Comments

i know about this website and i have tried here but i want to execute it in my system. It is not working on my computer
Change the single quote to double

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.