views:

36

answers:

1

Hi, I have a .jar file which has a command line interface. I want to call the jar file through command prompt and capture the output of the Jar file.

I have tried with the exec() command.

The command I have used is:

<?php
exec('java -jar D:\\Development\\Filehandler\\dist\\Filehandler.jar \ getConfigLang', $result);
echo $result;
echo $count = count($result);
for($i=0; $i<$count;$i++){
    print($result[$i]);
}

?>

The output for this was just '0 0'

Should something else be done before executing this command? like adding path etc??? I am using WAMP server. Please help me...

A: 

Well, you can try two approaches:

1) change current directory in PHP via function http://php.net/manual/en/function.chdir.php

<?php
chdir('D:\Development\Filehandler\dist');
exec('java -jar ./Filehandler.jar \ getConfigLang', $result);
...
?>

2) change .jar file: I don't know if it is possible but try to add these additional libraries with absolute paths.

MartyIX
Please, could you post here what solved your problem? Whether it was 1) or 2)?
MartyIX