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:
Maas Lalani
2021-10-29 16:52:38 -04:00
parent e4ae7004a5
commit acc4e08881
3 changed files with 13 additions and 5 deletions

View File

@@ -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 {

View File

@@ -45,7 +45,7 @@ func main() {
Language: "bash",
},
expected: code.Result{
Out: "",
Out: "exit status 127",
ExitCode: 1,
},
},