diff --git a/api.go b/api.go index 65bed1d..0cbf3df 100644 --- a/api.go +++ b/api.go @@ -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 { diff --git a/exec.go b/exec.go index c988e46..5e497b5 100644 --- a/exec.go +++ b/exec.go @@ -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)