开发者

Php exec with Java

开发者 https://www.devze.com 2023-01-26 19:37 出处:网络
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 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

精彩评论

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