Skip to content

os/exec: add example showing use of pipe #4290

@rogpeppe

Description

@rogpeppe
Cmd.StdoutPipe, Cmd.StdinPipe, Cmd.StderrPipe all close the client end of the pipe when
Wait returns. This is problematic when there's an independent goroutine that uses the
client end of the pipe. For example, this code can
fail to copy all the data from a command.

    c := exec.Command("some-command")
    r, err := c.StdoutPipe()
    if err != nil {...}
    go io.Copy(dest, r)
    c.Run()

Since all these methods return io.*Closer types, it seems reasonable to me that the
caller should have the responsibility for closing them.

Metadata

Metadata

Assignees

No one assigned

    Labels

    FrozenDueToAgeSuggestedIssues that may be good for new contributors looking for work to do.

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions