我试图在我的PHP代码的后端运行一个Jar文件.但是我没有得到它所需的输出.有一个jar文件在后台运行并返回给定的任何关键字和域的页面排名它.我正在附上代码,请向我建议任何解决方案,因为当我在终端上运行它时,它会提供正确的输出.
这是代码:
<?php
set_time_limit(0);
function returnJarPath()
{
$jarPath = $_SERVER['DOCUMENT_ROOT'] . "myFolder/tools_new/includes/Rank.jar";
return $jarPath;
}
$jar = returnJarPath();
$command = "java -jar $jar aspdotnet/microsoft.com";//Passing the Argument to the Jar file.
$shellOutput = shell_exec($command);
print "The Shell Output is : " ; var_dump($shellOutput);print "<br />";
exec($command,$executeCommmand);
print "The Exec returns the value : " ; var_dump($executeCommmand);print "<br />";
passthru($command,$passthruCommand);
print "The Passthru returns the value : " . $passthruCommand. "<br />";
?>
Run Code Online (Sandbox Code Playgroud)
我刚检查了apache的错误日志,我发现的最后一个错误是:
sh:java:找不到命令
但正如我已经说过的,我一直在通过SSH使用相同的命令来运行Java命令.所以没有这样的可能性,没有在服务器上安装JAVA.请帮我摆脱这个烂摊子......
如果 jar 文件写入标准输出,则可以使用 exec。
这是我如何使用它的示例:
may be first: exec("cd jar dir"); // if jar fine needs to be executed from the same dir
$output = exec("/usr/bin/java -jar $jar aspdotnet/microsoft.com");
Run Code Online (Sandbox Code Playgroud)
但正如你所说:
sh: java: command not found
Run Code Online (Sandbox Code Playgroud)
这意味着没有从 php 到 java 的路径别名。只需使用可执行文件 /usr/bin/java 的完整 java 路径即可。
| 归档时间: |
|
| 查看次数: |
9388 次 |
| 最近记录: |