func Shell2(env Env, dir, shellScript string, show bool) error { cmd := exec.Command("sh", "-v") cmd.Dir = dir if env != nil { //println(fmt.Sprintf("%#v\n", env.Environ())) cmd.Env = env.Environ() } shellScript = "env | grep CGO 1>&2\nset -x\n" + shellScript PrintScript(dir, env, shellScript) cmd.Stdin = bytes.NewBufferString(shellScript) if show { stderr, err := cmd.StderrPipe() if err != nil { return err } stdout, err := cmd.StdoutPipe() if err != nil { return err } if err = cmd.Start(); err != nil { return err } // Build tool cannot write anything to stdout, other than the result directory at the end shell := "sh" io.Copy(os.Stderr, iomisc.Combine(iomisc.PrefixReader(shell+"/err| ", stderr), iomisc.PrefixReader(shell+"/out| ", stdout))) } return cmd.Wait() }
func ForwardStderr(prefix string, stderr io.Reader) { go func() { io.Copy(os.Stderr, iomisc.PrefixReader(prefix+"/err| ", stderr)) }() }
func ForwardCombined(prefix string, stderr, stdout io.Reader) { go func() { io.Copy(os.Stderr, iomisc.Combine(iomisc.PrefixReader(prefix+"/err| ", stderr), iomisc.PrefixReader(prefix+"/out| ", stdout))) }() }