Skip to content

Commit 29c77ab

Browse files
runtime-compile
1 parent 5e49586 commit 29c77ab

File tree

2 files changed

+35
-1
lines changed

2 files changed

+35
-1
lines changed

runtime-compile/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
runtime-compile

runtime-compile/main.go

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ package main
77

88
import (
99
"encoding/json"
10+
"errors"
1011
"io"
1112
"os"
1213
"os/exec"
@@ -27,6 +28,38 @@ func main() {
2728
var testCaseOptions types.TestCaseOptions
2829
json.Unmarshal(testCaseJson, &testCaseOptions)
2930

30-
// compileCmd := exec.Command("g++", testCaseOptions.CompilerOptions.Flags...)
31+
args := append(testCaseOptions.CompilerOptions.Flags, "-x", "c++", "-")
32+
compileCmd := exec.Command("g++", args...)
33+
34+
compileCmdStdin, err := compileCmd.StdinPipe()
35+
if err != nil {
36+
panic(err)
37+
}
38+
39+
compileCmdStdout, err := compileCmd.StdoutPipe()
40+
if err != nil {
41+
panic(err)
42+
}
43+
44+
compileCmdStderr, err := compileCmd.StderrPipe()
45+
if err != nil {
46+
panic(err)
47+
}
48+
49+
go func() {
50+
io.Copy(compileCmdStdin, os.Stdin)
51+
compileCmdStdin.Close()
52+
}()
53+
54+
go io.Copy(os.Stderr, compileCmdStderr)
55+
go io.Copy(os.Stdout, compileCmdStdout)
56+
57+
err = compileCmd.Run()
58+
59+
var exitError *exec.ExitError
60+
61+
if errors.As(err, &exitError) {
62+
os.Exit(exitError.ExitCode())
63+
}
3164

3265
}

0 commit comments

Comments
 (0)