// cmdStream executes a command, and returns its stdout as a stream.
// If the command fails to run or doesn't complete successfully, an error
// will be returned, including anything written on stderr.
cmdStream executes a command, and returns its stdout as a stream.
If the command fails to run or doesn't complete successfully, an error
will be returned, including anything written on stderr.
// cmdStream executes a command and returns its stdout as a stream . // If the command fails to run or doesn ' t complete successfully an error // will be returned including anything written on stderr .
func cmdStream(cmd *exec.Cmd, input io.Reader) (io.ReadCloser, <-chan struct{}, error) {
        chdone := make(chan struct{})
        cmd.Stdin = input
        pipeR, pipeW := io.Pipe()
        cmd.Stdout = pipeW
        var errBuf bytes.Buffer
        cmd.Stderr = &errBuf
        if err := cmd.Start(); err != nil {
                return nil, nil, err
        }
        go func() {
                if err := cmd.Wait(); err != nil {
                        pipeW.CloseWithError(fmt.Errorf("%s: %s", err, errBuf.String()))
                } else {
                        pipeW.Close()
                }
                close(chdone)
        }()
        return pipeR, chdone, nil
}
func cmdStream ( cmd * exec . Cmd , input io . Reader ) ( io . ReadCloser , <- chan struct { } , error ) { chdone := make ( chan struct { } ) cmd . Stdin = input pipeR , pipeW := io . Pipe ( ) cmd . Stdout = pipeW var errBuf bytes . Buffer cmd . Stderr = & errBuf if err := cmd . Start ( ) ; err != nil { return nil , nil , err } go func ( ) { if err := cmd . Wait ( ) ; err != nil { pipeW . CloseWithError ( fmt . Errorf ( " " , err , errBuf . String ( ) ) ) } else { pipeW . Close ( ) } close ( chdone ) } ( ) return pipeR , chdone , nil }
cmdStream executes a command, and returns its stdout as a stream.
cmdStream executes a command and returns its stdout as a stream .
// Run the command and return the pipe // Copy stdout to the returned pipe