Executing .jar file from PHP through Command prompt
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\\File开发者_如何学Gohandler\\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...
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.
精彩评论