从 python 中编译 java
我正在制作一个应用程序,人们可以在其中上传 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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
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...
完全可能:只需使用
system
命令并调用 java 编译器。您可能需要设置类路径和类似的东西,但它应该可以正常工作。编辑:参见 http://docs.python.org/library/os.html# os.system 和 http://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.