php exec()& java发送参数 [英] php exec() & java send parameters
本文介绍了php exec()& java发送参数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想通过php连接到java并在php中打印结果。现在我想向java发送一个参数并将其返回给php以查看它是如何工作的。我怎样才能做到这一点?
到目前为止我有这个代码:
I want to connect to java via php and print the result out in php. Now I want to send a parameter to java and return it to php to see how it works. How can I do this? I have this code so far:
PHP:
exec("java jar/name.jar", $output);
print_r($output);
Java:
public class Main {
public static void main(String[] args) {
System.out.print(args[0]);
}
}
结果是
Array ( )
推荐答案
执行
exec("/full/path/to/java -jar jar/name.jar 2>&1", $output);
print_r($output);
因为
- 你的PHP env可能没有在路径中定义的java可执行文件(也不应该这样)
- jar文件用
java -jar执行
- 您希望
2>& 1
能够在输出中看到错误消息(从stderr重定向到stdout)
- your PHP env probably doesn't have java executable defined in the path (and it shouldn't, either)
- jar files are executed with
java -jar
- you'll want
2>&1
to be able to see error messages in the output (redirect from stderr to stdout)
这篇关于php exec()& java发送参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文