Esempio n. 1
0
 public boolean compile(String sol) throws ServerException {
   try {
     createSrcFile();
     File f = new File(workDir, srcFileName);
     FileWriter fw = new FileWriter(f);
     fw.write(sol);
     fw.close();
     exec(compileCmd, "", 2, 2048);
     File ef = new File(workDir, executableName);
     return ef.exists();
   } catch (Exception e) {
     throw UtilSrv.se("Can't compile.", e);
   }
 }
Esempio n. 2
0
 public boolean ok(String out, String reference) {
   try {
     File fo = File.createTempFile("homeworkeval", ".out");
     File fr = File.createTempFile("homeworkeval", ".ref");
     log.fine("Running custom validator.");
     save(out, fo);
     save(reference, fr);
     ArrayList<String> c = new ArrayList<String>();
     c.add(command);
     c.add(fo.getPath());
     c.add(fr.getPath());
     ProcessBuilder pb = new ProcessBuilder(c);
     Process p = pb.start();
     int rc = p.waitFor();
     fo.delete();
     fr.delete();
     log.fine("Custom validator " + command + " says " + rc);
     return rc == 0;
   } catch (Exception e) {
     // Assume NOK. Don't propagate info to the client.
     log.finer("exc: " + UtilSrv.describe(e));
     return false;
   }
 }