0

I am trying to execute a jar file from php in a windows environment. I want to send a string to a method in a jar file and get the output. Though i checked most of the posts related to this function still couldn't find the solution. Here is what i am executing.

<?php
$name="name";
$output = array();
exec('java -jar C:\Users\HP USER\Desktop\al\hel\out\artifacts\hel_jar\hel.jar', $output, $name);
print_r($output);

The output i am getting is "Array ( )"

Kushal Sharma
  • 5,978
  • 5
  • 25
  • 41
Jack
  • 1
  • 1
  • are you sure the `.jar` file outputs something? Also do you get any errors from `exec`?? – Nikos M. May 31 '15 at 15:49
  • you can also try to execute a comand with redirection and just read the contents of the file. e.g `exec("java -jar my.jar > output.txt"); $result = file_get_contents("output.txt");` – Nikos M. May 31 '15 at 15:50
  • What happens when you run that command as from the command line? – GhostCat May 31 '15 at 15:50
  • Capture stderr `2>&1` (or with a shell wrapper) to diagnose anything. – mario May 31 '15 at 15:51
  • The jar files works fine in command line.It outputs a string value. But im getting only as "Array()" when i run it in php. @NikosM. I tried ur code its also not outputting anything. – Jack May 31 '15 at 16:01
  • @mario i didnt get what 2>&1? and where to apply? – Jack May 31 '15 at 16:01
  • See the examples in the linked duplicate. Edit your question with further details once you've done so. – mario May 31 '15 at 16:07
  • i tried all those.I have put this after trying all those methods.Still its not working – Jack May 31 '15 at 16:22
  • Edit your question with what you tried. And the resulting error message. If you don't have an error message, or a log, then nobody can help. – mario May 31 '15 at 18:20

0 Answers0