Java shell_exec命令上的变量Concate
我必须从PHP执行一个jar文件,并且必须传递一个参数 我有这个功能Java shell_exec命令上的变量Concate,java,php,shell-exec,Java,Php,Shell Exec,我必须从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'
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 )
The command is: "C:\Program Files\Java\jre8\bin\java" -jar lesk.jar the cat and the roof
Array ()
但是,不是那样的
$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 ( [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 )
The command is: "C:\Program Files\Java\jre8\bin\java" -jar lesk.jar the cat and the roof
Array ()
当我打印变量命令时,我可以看到正确的句子,但不起作用。我读了两遍,我和猫头鹰完全混淆了我相信你不想要文件内容()你应该使用include\require,然后你仍然需要调用function@Dagon我必须使用文件获取内容()因为owls-dump.php返回一个json对象。@Dagon最重要的是owlParsed->句子是一个字符串(“猫和屋顶”,每个例子)