func (z *ZJGSUJudger) compile(user vjudger.UserInterface) { cmd := exec.Command("compiler", strconv.Itoa(user.GetLang()), z.workdir) err := cmd.Run() if err != nil { log.Println(err) } if cmd.ProcessState.String() != "exit status 0" { log.Println(cmd.ProcessState.String()) user.SetResult(config.JudgeCE) //compiler error } }
func (z *ZJGSUJudger) files(user vjudger.UserInterface, workdir string) { var codefilename string switch user.GetLang() { case config.LanguageC: codefilename = workdir + "/Main.c" case config.LanguageCPP: codefilename = workdir + "/Main.cc" case config.LanguageJAVA: codefilename = workdir + "/Main.java" } codefile, err := os.Create(codefilename) defer codefile.Close() _, err = codefile.WriteString(user.GetCode()) if err != nil { logger.Println("source code writing to file failed") } }
func (z *ZJGSUJudger) GetStatus(user vjudger.UserInterface) error { logger.Println("run solution") var out bytes.Buffer cmd := exec.Command("runner", strconv.Itoa(user.GetLang()), strconv.Itoa(z.time), strconv.Itoa(z.mem), z.workdir) cmd.Stdout = &out cmd.Run() sp := strings.Split(out.String(), " ") var err error Result, err := strconv.Atoi(sp[0]) if err != nil { logger.Println(err) logger.Println(Result) } user.SetResult(Result) Time, _ := strconv.Atoi(sp[1]) Mem, _ := strconv.Atoi(sp[2]) Mem = Mem / 1024 //b->Kb user.SetResource(Time, Mem, len(user.GetCode())) return nil }