예제 #1
0
 protected function compile($files)
 {
     global $CFG;
     $search = array('%SOURCES%', '%DEST%');
     $replace = array('"' . implode('" "', $files) . '"', '"' . onlinejudge_get_temp_dir() . '/a.out"');
     // construct compiler command
     $command = str_replace($search, $replace, self::$supported_languages[$this->language]);
     // run compiler and redirect stderr to stdout
     $output = array();
     $return = 0;
     exec($command . ' 2>&1', $output, $return);
     $this->task->compileroutput = str_replace(onlinejudge_get_temp_dir() . '/', '', implode("\n", $output));
     if ($return != 0) {
         // TODO: if the command can not be executed, it should be internal error
         $this->task->status = ONLINEJUDGE_STATUS_COMPILATION_ERROR;
     } else {
         $this->task->status = ONLINEJUDGE_STATUS_COMPILATION_OK;
     }
     return trim($replace[1], '"');
 }
 /**
  * Save files of current task to a temp directory
  *
  * @return array of the full path of saved files
  */
 protected function create_temp_files()
 {
     $dstfiles = array();
     $fs = get_file_storage();
     $files = $fs->get_area_files(get_context_instance(CONTEXT_SYSTEM)->id, 'local_onlinejudge', 'tasks', $this->task->id, 'sortorder', false);
     foreach ($files as $file) {
         $path = onlinejudge_get_temp_dir() . $file->get_filepath();
         $fullpath = $path . $file->get_filename();
         if (!check_dir_exists($path)) {
             throw new moodle_exception('errorcreatingdirectory', '', '', $path);
         }
         $file->copy_content_to($fullpath);
         $dstfiles[] = $fullpath;
     }
     return $dstfiles;
 }