PHP 与 Java 执行

发布于 2024-10-03 20:23:01 字数 241 浏览 0 评论 0原文

我在 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

鱼忆七猫命九 2024-10-10 20:23:01

来自文档

string exec ( string $command [, array &$output [, int &$return_var ]] )

如果存在输出参数,则指定的数组将填充命令的每一行输出

示例的每一行输出:

exec('java ' . $file, $output);
print_r($output);

From the docs:

string exec ( string $command [, array &$output [, int &$return_var ]] )

If the output argument is present, then the specified array will be filled with every line of output from the command

Example:

exec('java ' . $file, $output);
print_r($output);
随梦而飞# 2024-10-10 20:23:01

没关系。好的,它有效。您必须在输出上运行 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.

因为看清所以看轻 2024-10-10 20:23:01

您可能想要使用 popen() 或更通用的 proc_open()

You probably want to be using popen() or the even more general proc_open()

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文