Skip to content

Commit 59a6e10

Browse files
committed
update app judge
1 parent 03db268 commit 59a6e10

File tree

2 files changed

+39
-23
lines changed

2 files changed

+39
-23
lines changed

module/judge/judge_compileUnix.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import (
66
)
77

88
func CompileUnixC11(SubmissionID int, lang string) bool {
9-
cmd := exec.Command("gcc", getPath()+"/src/"+strconv.Itoa(SubmissionID)+"/main.c", "-o", getPath()+"/src/"+strconv.Itoa(SubmissionID)+"/main", "--std=c++11", "-lm")
9+
cmd := exec.Command("gcc", getPath()+"/src/"+strconv.Itoa(SubmissionID)+"/main.c", "-o", getPath()+"/src/"+strconv.Itoa(SubmissionID)+"/main", "--std=c++11", "-lm", "-DONLINE_JUDGE")
1010
err := cmd.Run()
1111

1212
if err != nil {
@@ -17,7 +17,7 @@ func CompileUnixC11(SubmissionID int, lang string) bool {
1717
}
1818

1919
func CompileUnixCPP11(SubmissionID int, lang string) bool {
20-
cmd := exec.Command("g++", getPath()+"/src/"+strconv.Itoa(SubmissionID)+"/main.cpp", "-o", getPath()+"/src/"+strconv.Itoa(SubmissionID)+"/main", "--std=c++11", "-lm")
20+
cmd := exec.Command("g++", getPath()+"/src/"+strconv.Itoa(SubmissionID)+"/main.cpp", "-o", getPath()+"/src/"+strconv.Itoa(SubmissionID)+"/main", "--std=c++11", "-lm", "-DONLINE_JUDGE")
2121
err := cmd.Run()
2222

2323
if err != nil {
@@ -28,7 +28,7 @@ func CompileUnixCPP11(SubmissionID int, lang string) bool {
2828
}
2929

3030
func CompileUnixCPP14(SubmissionID int, lang string) bool {
31-
cmd := exec.Command("g++", getPath()+"/src/"+strconv.Itoa(SubmissionID)+"/main.cpp", "-o", getPath()+"/src/"+strconv.Itoa(SubmissionID)+"/main", "--std=c++14", "-lm")
31+
cmd := exec.Command("g++", getPath()+"/src/"+strconv.Itoa(SubmissionID)+"/main.cpp", "-o", getPath()+"/src/"+strconv.Itoa(SubmissionID)+"/main", "--std=c++14", "-lm", "-DONLINE_JUDGE")
3232
err := cmd.Run()
3333

3434
if err != nil {
@@ -39,7 +39,7 @@ func CompileUnixCPP14(SubmissionID int, lang string) bool {
3939
}
4040

4141
func CompileUnixCPP17(SubmissionID int, lang string) bool {
42-
cmd := exec.Command("g++", getPath()+"/src/"+strconv.Itoa(SubmissionID)+"/main.cpp", "-o", getPath()+"/src/"+strconv.Itoa(SubmissionID)+"/main", "--std=c++17", "-lm")
42+
cmd := exec.Command("g++", getPath()+"/src/"+strconv.Itoa(SubmissionID)+"/main.cpp", "-o", getPath()+"/src/"+strconv.Itoa(SubmissionID)+"/main", "--std=c++17", "-lm", "-DONLINE_JUDGE")
4343
err := cmd.Run()
4444

4545
if err != nil {

module/judge/judge_runUnix.go

Lines changed: 35 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -17,18 +17,21 @@ func RunUnixBin(SubmissionID int, SubmissionPath string) bool {
1717
return false
1818
}
1919

20-
defer stdin.Close()
21-
2220
stdout, err := os.OpenFile(SubmissionPath+"/data.out", os.O_CREATE|os.O_WRONLY, 0600)
2321

2422
if err != nil {
2523
return false
2624
}
2725

28-
defer stdout.Close()
29-
3026
subProcess.Stdout = stdout
31-
subProcess.Stderr = os.Stderr
27+
28+
stderr, err := os.OpenFile(SubmissionPath+"/data.err", os.O_CREATE|os.O_WRONLY, 0600)
29+
30+
if err != nil {
31+
return false
32+
}
33+
34+
subProcess.Stderr = stderr
3235

3336
if err = subProcess.Start(); err != nil {
3437
return false
@@ -40,20 +43,22 @@ func RunUnixBin(SubmissionID int, SubmissionPath string) bool {
4043
return false
4144
}
4245

43-
defer fi.Close()
44-
4546
inputBuff := bufio.NewReader(fi)
4647

4748
for {
4849
a, _, c := inputBuff.ReadLine()
4950
if c == io.EOF {
51+
stdin.Close()
5052
break
5153
}
5254
io.WriteString(stdin, string(a)+"\n")
5355
}
5456

5557
subProcess.Wait()
5658

59+
stdout.Close()
60+
fi.Close()
61+
5762
return true
5863
}
5964

@@ -66,18 +71,22 @@ func RunPython2(SubmissionID int, SubmissionPath string) bool {
6671
return false
6772
}
6873

69-
defer stdin.Close()
70-
7174
stdout, err := os.OpenFile(SubmissionPath+"/data.out", os.O_CREATE|os.O_WRONLY, 0600)
7275

7376
if err != nil {
7477
return false
7578
}
7679

77-
defer stdout.Close()
78-
7980
subProcess.Stdout = stdout
8081

82+
stderr, err := os.OpenFile(SubmissionPath+"/data.err", os.O_CREATE|os.O_WRONLY, 0600)
83+
84+
if err != nil {
85+
return false
86+
}
87+
88+
subProcess.Stderr = stderr
89+
8190
if err = subProcess.Start(); err != nil {
8291
return false
8392
}
@@ -88,20 +97,22 @@ func RunPython2(SubmissionID int, SubmissionPath string) bool {
8897
return false
8998
}
9099

91-
defer fi.Close()
92-
93100
inputBuff := bufio.NewReader(fi)
94101

95102
for {
96103
a, _, c := inputBuff.ReadLine()
97104
if c == io.EOF {
105+
stdin.Close()
98106
break
99107
}
100108
io.WriteString(stdin, string(a)+"\n")
101109
}
102110

103111
subProcess.Wait()
104112

113+
stdout.Close()
114+
fi.Close()
115+
105116
return true
106117
}
107118

@@ -114,18 +125,22 @@ func RunPython3(SubmissionID int, SubmissionPath string) bool {
114125
return false
115126
}
116127

117-
defer stdin.Close()
118-
119128
stdout, err := os.OpenFile(SubmissionPath+"/data.out", os.O_CREATE|os.O_WRONLY, 0600)
120129

121130
if err != nil {
122131
return false
123132
}
124133

125-
defer stdout.Close()
126-
127134
subProcess.Stdout = stdout
128135

136+
stderr, err := os.OpenFile(SubmissionPath+"/data.err", os.O_CREATE|os.O_WRONLY, 0600)
137+
138+
if err != nil {
139+
return false
140+
}
141+
142+
subProcess.Stderr = stderr
143+
129144
if err = subProcess.Start(); err != nil {
130145
return false
131146
}
@@ -136,8 +151,6 @@ func RunPython3(SubmissionID int, SubmissionPath string) bool {
136151
return false
137152
}
138153

139-
defer fi.Close()
140-
141154
inputBuff := bufio.NewReader(fi)
142155

143156
for {
@@ -150,6 +163,9 @@ func RunPython3(SubmissionID int, SubmissionPath string) bool {
150163

151164
subProcess.Wait()
152165

166+
stdout.Close()
167+
fi.Close()
168+
153169
return true
154170
}
155171

0 commit comments

Comments
 (0)