mirror of
https://github.com/maaslalani/slides.git
synced 2026-01-09 14:28:05 -05:00
Fix: bug where old file name would be reused
There was a bug where the command would reference an old file name which would be deleted which meant that the code block would not execute on future executions and only work the first time.
This commit is contained in:
@@ -80,6 +80,8 @@ func Execute(code Block) Result {
|
||||
ExitCode: ExitCodeInternalError,
|
||||
}
|
||||
}
|
||||
|
||||
defer f.Close()
|
||||
defer os.Remove(f.Name())
|
||||
|
||||
_, err = f.WriteString(code.Code)
|
||||
@@ -108,14 +110,19 @@ func Execute(code Block) Result {
|
||||
start := time.Now()
|
||||
|
||||
for _, c := range language.Commands {
|
||||
var command []string
|
||||
// replace <file>, <name> and <path> in commands
|
||||
for i, v := range c {
|
||||
c[i] = repl.Replace(v)
|
||||
for _, v := range c {
|
||||
command = append(command, repl.Replace(v))
|
||||
}
|
||||
// execute and write output
|
||||
cmd := exec.Command(c[0], c[1:]...)
|
||||
cmd := exec.Command(command[0], command[1:]...)
|
||||
out, err := cmd.Output()
|
||||
output.Write(out)
|
||||
if err != nil {
|
||||
output.Write([]byte(err.Error()))
|
||||
} else {
|
||||
output.Write(out)
|
||||
}
|
||||
|
||||
// update status code
|
||||
if err != nil {
|
||||
|
||||
@@ -45,7 +45,7 @@ func main() {
|
||||
Language: "bash",
|
||||
},
|
||||
expected: code.Result{
|
||||
Out: "",
|
||||
Out: "exit status 127",
|
||||
ExitCode: 1,
|
||||
},
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user