示例#1
0
 public String execRecognizer() {
   try {
     String inputFile = new File(tmpdir, "input").getAbsolutePath();
     String[] args =
         new String[] {"java", "-classpath", tmpdir + pathSep + CLASSPATH, "Test", inputFile};
     // String cmdLine = "java -classpath "+CLASSPATH+pathSep+tmpdir+" Test " + new File(tmpdir,
     // "input").getAbsolutePath();
     // System.out.println("execParser: "+cmdLine);
     Process process = Runtime.getRuntime().exec(args, null, new File(tmpdir));
     StreamVacuum stdoutVacuum = new StreamVacuum(process.getInputStream());
     StreamVacuum stderrVacuum = new StreamVacuum(process.getErrorStream());
     stdoutVacuum.start();
     stderrVacuum.start();
     process.waitFor();
     stdoutVacuum.join();
     stderrVacuum.join();
     String output = null;
     output = stdoutVacuum.toString();
     if (stderrVacuum.toString().length() > 0) {
       this.stderrDuringParse = stderrVacuum.toString();
       System.err.println("exec stderrVacuum: " + stderrVacuum);
     }
     return output;
   } catch (Exception e) {
     System.err.println("can't exec recognizer");
     e.printStackTrace(System.err);
   }
   return null;
 }
  protected boolean compile(String fileName) {
    String compiler = "javac";
    String classpathOption = "-classpath";

    if (jikes != null) {
      compiler = jikes;
      classpathOption = "-bootclasspath";
    }

    String[] args =
        new String[] {
          compiler,
          "-d",
          tmpdir,
          classpathOption,
          tmpdir + pathSep + CLASSPATH,
          tmpdir + "/" + fileName
        };
    String cmdLine =
        compiler
            + " -d "
            + tmpdir
            + " "
            + classpathOption
            + " "
            + tmpdir
            + pathSep
            + CLASSPATH
            + " "
            + fileName;
    // System.out.println("compile: "+cmdLine);
    File outputDir = new File(tmpdir);
    try {
      Process process = Runtime.getRuntime().exec(args, null, outputDir);
      StreamVacuum stdout = new StreamVacuum(process.getInputStream());
      StreamVacuum stderr = new StreamVacuum(process.getErrorStream());
      stdout.start();
      stderr.start();
      process.waitFor();
      stdout.join();
      stderr.join();
      if (stdout.toString().length() > 0) {
        System.err.println("compile stdout from: " + cmdLine);
        System.err.println(stdout);
      }
      if (stderr.toString().length() > 0) {
        System.err.println("compile stderr from: " + cmdLine);
        System.err.println(stderr);
      }
      int ret = process.exitValue();
      return ret == 0;
    } catch (Exception e) {
      System.err.println("can't exec compilation");
      e.printStackTrace(System.err);
      return false;
    }
  }
示例#3
0
  public String execClass(String className) {
    /* HOW TO GET STDOUT?
    try {
    	ClassLoader cl_new = new DirectoryLoader(new File(tmpdir));
    	Class compiledClass = cl_new.loadClass(className);
    	Method m = compiledClass.getMethod("main");
    	m.invoke(null);
    } catch (Exception ex) {
    	ex.printStackTrace(System.err);
    }
    */

    try {
      String[] args =
          new String[] {
            "java",
            "-classpath",
            tmpdir + pathSep + CLASSPATH,
            className,
            new File(tmpdir, "input").getAbsolutePath()
          };
      // String cmdLine = "java -classpath "+CLASSPATH+pathSep+tmpdir+" Test " + new File(tmpdir,
      // "input").getAbsolutePath();
      // System.out.println("execParser: "+cmdLine);
      Process process = Runtime.getRuntime().exec(args, null, new File(tmpdir));
      StreamVacuum stdoutVacuum = new StreamVacuum(process.getInputStream());
      StreamVacuum stderrVacuum = new StreamVacuum(process.getErrorStream());
      stdoutVacuum.start();
      stderrVacuum.start();
      process.waitFor();
      stdoutVacuum.join();
      stderrVacuum.join();
      String output = null;
      output = stdoutVacuum.toString();
      if (stderrVacuum.toString().length() > 0) {
        this.stderrDuringParse = stderrVacuum.toString();
        System.err.println("exec stderrVacuum: " + stderrVacuum);
      }
      return output;
    } catch (Exception e) {
      System.err.println("can't exec recognizer");
      e.printStackTrace(System.err);
    }
    return null;
  }