Skip to content

Commit

Permalink
fixed stderr output
Browse files Browse the repository at this point in the history
  • Loading branch information
bertramn committed May 3, 2016
1 parent 21ff613 commit a4c889e
Showing 1 changed file with 18 additions and 4 deletions.
22 changes: 18 additions & 4 deletions ansible-playbook.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,17 +36,31 @@ func main() {
}
cmd := exec.Command("c:\\cygwin\\bin\\bash.exe", "-c", strings.Join(args[:], " "))

// echo stdin back to console
cmdReader, err := cmd.StdoutPipe()
if err != nil {
fmt.Fprintln(os.Stderr, "Error creating "+executable+" wrapper stdout pipeline", err)
os.Exit(1)
}

// echo stdin back to console
scanner := bufio.NewScanner(cmdReader)
outScanner := bufio.NewScanner(cmdReader)
go func() {
for outScanner.Scan() {
fmt.Printf("%s\n", outScanner.Text())
}
}()

// echo stderr back to console
errReader, err := cmd.StderrPipe()
if err != nil {
fmt.Fprintln(os.Stderr, "Error creating "+executable+" wrapper stderr pipeline", err)
os.Exit(1)
}

errScanner := bufio.NewScanner(errReader)
go func() {
for scanner.Scan() {
fmt.Printf("%s\n", scanner.Text())
for errScanner.Scan() {
fmt.Fprintln(os.Stderr, errScanner.Text())
}
}()

Expand Down

0 comments on commit a4c889e

Please sign in to comment.