-
Notifications
You must be signed in to change notification settings - Fork 0
/
runner.go
executable file
·97 lines (72 loc) · 1.69 KB
/
runner.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
package main
import (
"os/exec"
"os"
"fmt"
)
func ClearScreen() {
cmd := exec.Command("cmd", "/c", "cls")
cmd.Stdout = os.Stdout
cmd.Run()
}
type CompileError struct {
er error
out []byte
}
func (c CompileError) Error() string {
return fmt.Sprint("Compiler error: ", c.er, "\n\n", string(c.out))
}
type RunError struct {
er error
out []byte
}
func (c RunError) Error() string {
str := string(c.out) + "\n_________________________________________"
if c.er == nil {
return str
}
return fmt.Sprint("Run error: ", c.er, "\n\n", str)
}
func Test(o Out, pid int) error {
// First compile it
o("\nCompiling...")
output, err := exec.Command("go", "build", "-o", "test.exe", GetFile(pid)).CombinedOutput()
if err != nil {
return CompileError{err, output}
}
// Run it!
o("\nRunning...\n")
output, err = exec.Command("test.exe").CombinedOutput()
if err != nil || len(output) > 0 {
return RunError{err, output}
}
return nil
}
func WriteOut(pid int) error {
fi := GetFile(pid)
if f, err := os.Create(fi); err != nil {
return err
} else {
WriteDefault(pid, f)
f.Close()
if err = exec.Command("go", "fmt", fi).Run(); err != nil {
return err
}
}
return nil
}
func Edit(pid int) error {
// Check to see if it exists
fi := GetFile(pid)
if _, err := os.Stat(fi); err != nil {
fmt.Println("STAT err: ", err)
if err := WriteOut(pid); err != nil {
return err
}
}
return exec.Command(`C:\Program Files (x86)\Notepad++\notepad++.exe`, fi).Run()
}
func ShowHelp(pid int) error {
f := Probs[pid].Help
return exec.Command("cmd", "/c", "start", f).Run()
}