I have a web app running on a LAMP stack that allows users to write java code into an HTML form, but depending on whether or not that code compiles successfully, I want to do different things.

我有一个在LAMP堆栈上运行的Web应用程序,允许用户将Java代码写入HTML表单,但是根据代码是否成功编译,我想做不同的事情。

The way I have it currently is that the PHP program would generate a .java file using user's input, execute it on the server (I have the security part taken care of), and then check to see if any errors were output.

我目前的方式是PHP程序将使用用户的输入生成.java文件,在服务器上执行它(我有安全部分处理),然后检查是否输出任何错误。

I know that Java prints errors out using the System.err stream, is there a way for me to tell if that output anything to the console? Like a way to listen and distinguish output streams of a program?

我知道Java使用System.err流输出错误,有没有办法让我告诉控制台是否有任何输出?像一种监听和区分程序输出流的方法?

1 个解决方案

#1


You can check the javac exit code. Here is a list of the javac exit code:

您可以查看javac退出代码。以下是javac退出代码的列表:

static final int
    EXIT_OK = 0,        // Compilation completed with no errors.
    EXIT_ERROR = 1,     // Completed but reported errors.
    EXIT_CMDERR = 2,    // Bad command-line arguments
    EXIT_SYSERR = 3,    // System error or resource exhaustion.
    EXIT_ABNORMAL = 4;  // Compiler terminated abnormally

References: http://bugs.java.com/view_bug.do?bug_id=7014715

Since Java 6, you can programmatically call the Java compiler (if provided). See this: ToolProvider#getSystemJavaCompiler

从Java 6开始,您可以以编程方式调用Java编译器(如果提供)。请参阅:ToolProvider#getSystemJavaCompiler

更多相关文章

  1. 如何获得嵌入式Jetty Web服务器来转储其JSP的临时Java代码
  2. 急求用jersey2.x+spring3.x 开发rest webservice Java代码实例
  3. “java.exe”已退出,代码为 1。
  4. Java错误:线程“main”中的异常java.lang.ArrayIndexOutOfBoundsE
  5. 不幸的是,在声明按钮时,模拟器中出现了错误
  6. Java 编程下的同步代码块(售票员)
  7. JAVA 关于图片上传的代码
  8. 当我运行.jar时,在java.library中会得到一个“No lwjgl”。路线”
  9. 导入证书后的Java Keytool错误,“Keytool error: Java .io。FileN

随机推荐

  1. Android APK文件在电脑上面运行方法
  2. Android中数据存储----SQLite数据库
  3. Android屏幕密度(Density)和分辨率的关系
  4. Android = Java
  5. Android中解决图像解码导致的OOM问题
  6. Android(安卓)studio 下载安装
  7. Activity 组件的启动流程
  8. Android 学习笔记——利用JNI技术在Andro
  9. Android HAL
  10. Android中运行Tensorflow程序2-编写自己