Commit 9e2eb387 authored by Sebastian Stark's avatar Sebastian Stark

redirect stdout and stderr of rsync to log output

parent ca100abe
......@@ -5,8 +5,10 @@
package main
import (
"bufio"
"errors"
"fmt"
"io"
"log"
"os"
"os/exec"
......@@ -60,13 +62,27 @@ func createRsyncCommand(sn *snapshot, base *snapshot) *exec.Cmd {
// error channel the caller can receive a return status from.
func runRsyncCommand(cmd *exec.Cmd) (chan error, error) {
var err error
cmd.Stdout = os.Stdout
cmd.Stderr = os.Stderr
stdout, err := cmd.StdoutPipe()
if err != nil {
return nil, err
}
stderr, err := cmd.StderrPipe()
if err != nil {
return nil, err
}
debugf("starting rsync command")
err = cmd.Start()
if err != nil {
return nil, err
}
multi := io.MultiReader(stdout, stderr)
in := bufio.NewScanner(multi)
for in.Scan() {
log.Printf("(rsync) %s", in.Text())
}
if err := in.Err(); err != nil {
log.Printf("error scanning rsync output: %s", err)
}
done := make(chan error)
go func() {
time.Sleep(time.Second)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment