gpt4 book ai didi

java - PHP 运行 java jar 文件,参数作为 php 变量

转载 作者:行者123 更新时间:2023-12-01 15:27:17 29 4
gpt4 key购买 nike

您好,我正在尝试从 PHP 5 执行 jar

这是我正在执行的代码:

$command = '"java -jar WEB-INF\\lib\\FileReceiver.jar '.$address.' '.$service_port.' \"'.$command.'\" \"'.$filePath.'\""';
exec($command, $out);

但是 jar 没有被执行。我已在 firebug 中记录了 $command 变量,并获取输出并插入到代码中,例如:

exec("java -jar WEB-INF\lib\FileReceiver.jar 127.0.1.1 2018 \"docs/document.txt \" \"C:\\apache-tomcat-7.0.26\\webapps\\test\\downloads\\doument.txt\"", $out);

给出正确的输出。我不明白为什么硬编码它可以工作,但包含相同信息的变量却不能。

有人可以帮我吗?

谢谢

最佳答案

尝试这样

$command = escapeshellarg($address).' '.escapeshellarg($service_port).' '.escapeshellarg($command).' '.escapeshellarg($filePath).' ';

exec('java -jar WEB-INF\\lib\\FileReceiver.jar '.$command, $out);

关于java - PHP 运行 java jar 文件,参数作为 php 变量,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10004196/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com