我必须从PHP执行一个jar文件,我必须传递一个参数。
我有这个功能
function sensesOfSentence($sentence){
$command = sprintf('"C:\Program Files\Java\jre8\bin\java" -jar lesk.jar %s', $sentence);
return json_decode(shell_exec($command));
}
以这种方式运作
$s = 'the cat and the roof'
echo sensesOfSentence($s);
输出
The command is: "C:\Program Files\Java\jre8\bin\java" -jar lesk.jar the cat and the roof
Array ( [0] => any of several large cats typically able to roar and living in the wild [1] => a protective covering that covers or forms the top of a building )
但是,不是那样的
$owlParsedJson = file_get_contents('owls-dump.php');
$owlParsed = json_decode($owlParsedJson);
echo sensesOfSentence(owlParsed->sentence);
输出
The command is: "C:\Program Files\Java\jre8\bin\java" -jar lesk.jar the cat and the roof
Array ()
当我打印变量命令时,我可以看到正确的句子,但是要正常工作。