fix: make stdout/stderr optional

pull/291/head
sammyette 2024-04-27 13:23:03 -04:00
parent 960badb5df
commit da92f6b7b4
Signed by: sammyette
GPG Key ID: 904FC49417B44DCD
2 changed files with 17 additions and 7 deletions

10
api.go
View File

@ -203,9 +203,13 @@ func hlrun(t *rt.Thread, c *rt.GoCont) (rt.Cont, error) {
stderrStream = f
}
strms = &streams{
stdout: stdoutStream.Handle(),
stderr: stderrStream.Handle(),
strms = &streams{}
if stdoutStream != nil {
strms.stdout = stdoutStream.Handle()
}
if stderrStream != nil {
strms.stderr = stderrStream.Handle()
}
} else {
if !terminalOut {

14
exec.go
View File

@ -272,11 +272,17 @@ func execCommand(cmd string, strms *streams) (io.Writer, io.Writer, error) {
runner, _ := interp.New()
if strms == nil {
strms = &streams{
stdout: os.Stdout,
stderr: os.Stderr,
}
strms = &streams{}
}
if strms.stdout == nil {
strms.stdout = os.Stdout
}
if strms.stderr == nil {
strms.stderr = os.Stderr
}
interp.StdIO(os.Stdin, strms.stdout, strms.stderr)(runner)
buf := new(bytes.Buffer)