开发者

Php exec with Java

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 c开发者_如何学Goan I get that output through exec() in php?

Thanks!


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);


nevermind. Okay, it works. You must run a print_r on the output to print the array, then you will see standard output.


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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜