Skip to content
This repository has been archived by the owner on May 3, 2022. It is now read-only.

Commit

Permalink
update to make output from command_driver available immediately
Browse files Browse the repository at this point in the history
  • Loading branch information
simongdavies committed May 17, 2019
1 parent d4e0d12 commit a895b62
Showing 1 changed file with 31 additions and 3 deletions.
34 changes: 31 additions & 3 deletions pkg/driver/command_driver.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"bytes"
"encoding/json"
"fmt"
"io"
"os"
"os/exec"
"strings"
Expand Down Expand Up @@ -71,7 +72,34 @@ func (d *CommandDriver) exec(op *driver.Operation) error {
}
cmd.Env = pairs
cmd.Stdin = bytes.NewBuffer(data)
out, err := cmd.CombinedOutput()
fmt.Fprintln(op.Out, string(out))
return err

// Make stdout and stderr from driver available immediately

stdout, err := cmd.StdoutPipe()
if err != nil {
return fmt.Errorf("Setting up output handling for driver (%s) failed: %v", d.Name, err)
}

go func() {

// Errors not handled here as they only prevent output from the driver being shown, errors in the command execution are handled when command is executed

io.Copy(op.Out, stdout)
}()
stderr, err := cmd.StderrPipe()
if err != nil {
return fmt.Errorf("Setting up error output handling for driver (%s) failed: %v", d.Name, err)
}
go func() {

// Errors not handled here as they only prevent output from the driver being shown, errors in the command execution are handled when command is executed

io.Copy(op.Out, stderr)
}()

if err = cmd.Start(); err != nil {
return fmt.Errorf("Start of driver (%s) failed: %v", d.Name, err)
}

return cmd.Wait()
}

0 comments on commit a895b62

Please sign in to comment.