-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>
Sumit Kumar
  • 402
  • 1
  • 6
  • 26
  • 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. – arkascha Feb 07 '14 at 12:02
  • 1
    see http://stackoverflow.com/questions/278868/calling-java-from-php-exec – websupporter Feb 07 '14 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. – Sumit Kumar Feb 07 '14 at 12:09

1 Answers1

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

Kaushik
  • 2,072
  • 1
  • 23
  • 31