title: How to capture return value from JAR in PHP and display it
body: <p>I have following JAVA program which has been converted to JAR file and placed in the same directory as my PHP file.
  So basically it takes an argument passed by PHP and displays it</p>
  
  <pre><code>public class Test {
      public static void main(String[] args) throws Exception {
          //Takes the value passed from the PHP
          String Name = (new String(args[0])).toString(); 
          //This will be treated as Output Parameter which will be returned to PHP
          System.out.println("Return to PHP"); 
  
      }
  }
  </code></pre>
  
  <p>Below is my PHP code which will execute the JAR file and pass the required 1 parameter to the JAR.</p>
  
  <pre><code>&lt;?php
  
  $arg1 = "My_INPUT_PARAMETER";
  
  shell_exec("java -jar TEST.jar $arg1");
  echo "Done";
  
  ?&gt;
  </code></pre>
  
  <p>I read somewhere that what ever the placed in Sysout (System.out.println) will be treated as output parameter or Return value to PHP.
  So in my case it will be String "Return to PHP".</p>
  
  <p>But I am not able to get the value to PHP and display it.</p>
  
  <p>I tried placing a output value in the exec statement but its not working.
  I tried below code but its throwing me error.</p>
  
  <pre><code>&lt;?php
  
  $arg1 = "My_INPUT_PARAMETER";
  $output = '';
  
  shell_exec("java -jar TEST.jar $arg1", $output);
  echo "Done";
  echo $output;
  
  ?&gt;
  </code></pre>
  
  <p>Can anyone help me out here, How can I get a return value from PHP or output parameter from PHP and display it or use it in my PHP and continue with other execution part.</p>