Executing .jar file from PHP through Command promp

2019-07-18 16:04发布

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...

1条回答
We Are One
2楼-- · 2019-07-18 16:31

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.

查看更多
登录 后发表回答