diff --git a/commands/eval.go b/commands/eval.go index 10d77e1e28bd33f8b0342b1e3b3e29d76f054ad1..7eacfa6e7082cb73476891b47dacd56b42e62d5e 100644 --- a/commands/eval.go +++ b/commands/eval.go @@ -1,10 +1,12 @@ package commands import ( + "bytes" "fmt" "io/fs" "io/ioutil" "os" + "os/exec" "strings" "time" @@ -42,6 +44,18 @@ func EvalCommand(ctx CommandHandler.Context, _ []string) error { ctx.Reply(err.Error()) return nil } - ctx.Reply(fmt.Sprintf("Wrote code to %s.go, ready to run.", uuidvar)) + ctx.Reply(fmt.Sprintf("Wrote code to %s.go, trying to run...", uuidvar)) + cmd := exec.Command("go", "run", fmt.Sprintf("./evals/%s.go", uuidvar)) + var outb bytes.Buffer + cmd.Stdout = &outb + err = cmd.Run() + if err != nil { + ctx.Reply(err.Error()) + return nil + } + + ctx.Reply("Output:") + time.Sleep(1 * time.Second) + ctx.Reply(outb.String()) return err }