从网站上的PHP脚本运行Java类文件 [英] Run Java class file from PHP script on a website

查看:81
本文介绍了从网站上的PHP脚本运行Java类文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个网站,希望能够允许用户从网站上运行服务器上的Java文件。

I have a website and want to be able to allow the user to run a Java file on the server from the website.

我希望用户点击一个按钮,该按钮将在服务器上运行Java文件,Java程序打印到标准输出的任何内容都将打印在网站上供用户查看。

I want the user to click a button which will run the Java file on the server AND anything printed to standard-out by the Java program will be printed out on the website for the user to see.

如何做到这一点(从PHP调用Java程序并将标准从Java文件实时提供回PHP网站) ?

How can this be done (call Java program from PHP and feed the standard out from the Java file back to the PHP website in real time)?

更新:

感谢您解答如何运行Java来自PHP的程序。但是我也希望能够,因为Java程序正在打印到stdout,它将在执行时打印出大量文本,以便能够在网页上打印出来,以便用户可以看到Java程序正在执行中。

Thanks for the answers on how to run the Java program from PHP. However I also want to be able, as the Java program is printing to stdout where it will be printing out a lot of text as it is executing, to be able to print this out on the webpage so that the user can see what stage the Java program is in its execution.

如何做到这一点是否需要任何额外的AJAX或JavaScript或类似的东西?

How can this be done and does it require any additional AJAX or JavaScript or anything like that?

推荐答案

PHP exec()函数是要走的路,但你应该 非常小心允许执行的内容..换句话说,不依赖于用户输入,因为它可能会危及整个服务器。

The PHP exec() function is the way to go, but you should be very careful in what you allow to executed.. in other words don't rely on user input as it could potentially compromise your entire server.

调用Java应用程序使用exec的启动器,你可以从PHP执行任何Java应用程序,例如

Calling the Java application launcher using exec, you can execute any Java application from PHP, e.g.

<?php exec("java -jar file.jar arguments", $output); ?>

这篇关于从网站上的PHP脚本运行Java类文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆