Skip to content

Commit 5051671

Browse files
tomlanyonianlancetaylor
authored andcommitted
os/exec: update docs for cmd.Std{out,err} and cmd.Wait to clarify how copying is done
Fixes #22610. Change-Id: I172fe1d1941a8a2750af7ee75f7af7e81a702c40 Reviewed-on: https://go-review.googlesource.com/76320 Reviewed-by: Ian Lance Taylor <[email protected]>
1 parent ecc8650 commit 5051671

File tree

1 file changed

+14
-6
lines changed

1 file changed

+14
-6
lines changed

src/os/exec/exec.go

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -92,8 +92,17 @@ type Cmd struct {
9292
// If either is nil, Run connects the corresponding file descriptor
9393
// to the null device (os.DevNull).
9494
//
95-
// If Stdout and Stderr are the same writer, and have a type that can be compared with ==,
96-
// at most one goroutine at a time will call Write.
95+
// If either is an *os.File, the process's standard output or standard
96+
// error, respectively, are connected directly to that file. Otherwise,
97+
// if either is not nil, during the execution of the command a separate
98+
// goroutine reads from the process's standard output or standard error
99+
// and delivers that to Stdout or Stderr. In this case, Wait does not
100+
// complete until the goroutine stops copying, either because it has
101+
// reached the end of Stdin (EOF or a read error) or because writing to
102+
// the pipe returned an error.
103+
//
104+
// If Stdout and Stderr are the same writer, and have a type that can
105+
// be compared with ==, at most one goroutine at a time will call Write.
97106
Stdout io.Writer
98107
Stderr io.Writer
99108

@@ -190,7 +199,7 @@ func (c *Cmd) argv() []string {
190199
}
191200

192201
// skipStdinCopyError optionally specifies a function which reports
193-
// whether the provided the stdin copy error should be ignored.
202+
// whether the provided stdin copy error should be ignored.
194203
// It is non-nil everywhere but Plan 9, which lacks EPIPE. See exec_posix.go.
195204
var skipStdinCopyError func(error) bool
196205

@@ -429,9 +438,8 @@ func (e *ExitError) Error() string {
429438
// error is of type *ExitError. Other error types may be
430439
// returned for I/O problems.
431440
//
432-
// If c.Stdin is not an *os.File, Wait also waits for the I/O loop
433-
// copying from c.Stdin into the process's standard input
434-
// to complete.
441+
// If any of c.Stdin, c.Stdout or c.Stderr are not an *os.File, Wait also waits
442+
// for the respective I/O loop copying to or from the process to complete.
435443
//
436444
// Wait releases any resources associated with the Cmd.
437445
func (c *Cmd) Wait() error {

0 commit comments

Comments
 (0)