PHP 与 Java 执行
我在 php 中有一个有效的 exec("java $file") 命令,但问题是我不确定如何从 java 程序获取标准输出。
我意识到还有第二个参数(例如, exec("java $file", $output) ),但这似乎没有从 java 程序返回输出。
例如,如果我有一个 java 程序,其中只有一个 println("Hello World") ,我如何通过 php 中的 exec() 获得该输出?
谢谢!
I have a working exec("java $file") command in php, but the problem is that I'm not sure how to get standard output from a java program.
I realize that there is a second parameter (for example, exec("java $file", $output) ) but that doesn't seem to return output from a java program.
For example, if I have a java program with just a println("Hello World") in it, how can I get that output through exec() in php?
Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
来自文档:
示例的每一行输出:
From the docs:
Example:
没关系。好的,它有效。您必须在输出上运行 print_r 来打印数组,然后您将看到标准输出。
nevermind. Okay, it works. You must run a print_r on the output to print the array, then you will see standard output.
您可能想要使用
popen()
或更通用的proc_open()
You probably want to be using
popen()
or the even more generalproc_open()