从 python 中编译 java

发布于 2024-11-29 07:16:30 字数 143 浏览 5 评论 0原文

我正在制作一个应用程序,人们可以在其中上传 java 代码并用它做一些事情。

我正在制作的应用程序是用 Python 编写的。我想知道是否可以从 python 中调用“javac”命令,为了编译上传的 java 文件,

我也使用 JPype

I'm making an application where people can upload a java code and do stuff with it.

The application i'm making is in Python. I was wondering whether it was possible to call the 'javac' command from within python, in order to compile the uploaded java file

I'm also using JPype

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(2

╰つ倒转 2024-12-06 07:16:30

http://docs.python.org/library/subprocess.html

但是您确定允许人们提交任意代码是个好主意吗?有一些安全方面需要考虑......

http://docs.python.org/library/subprocess.html

But are you sure that allowing people to submit arbitrary code is a good idea? There are security aspects of that to consider...

以为你会在 2024-12-06 07:16:30

完全可能:只需使用 system 命令并调用 java 编译器。您可能需要设置类路径和类似的东西,但它应该可以正常工作。

编辑:参见 http://docs.python.org/library/os.html# os.systemhttp://docs.python.org/library/subprocess.html#module-subprocess 了解有关调用子进程的详细信息。您可能希望捕获输出,以便在发生编译错误时返回给用户。

Entirely possible: just use the system command and invoke the java compiler. You'll probably need to set class paths and things of that nature, but it should work fine.

EDIT: see http://docs.python.org/library/os.html#os.system and http://docs.python.org/library/subprocess.html#module-subprocess for detail on invoking sub processes. You'll probably want to capture the output to return to the user in the event of a compile error.

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