Can someone help me understand why pw
(the writer) is scheduled for closing in Start()?
I would expect pw
to be closed together with pr
( the reader) in Wait().
closeAfterStart
and closeAfterwait
are two slices of io.Closers
which are called respectively ins Start
and Wait
of cmd
Struct. Now, why is this? both these are basically buffers(slices) which either need to be written into read off of. Depending on whether they are currently in use, they are closed. for example StdInPipe
requires reading first and then writing to, therefore the pr
is included in closeAfterStart
and pw
in closeAfterWait
. The reverse is done for StdOutPipe
.
The program is simply closing off the buffers which it doesn't need anymore in the code. In StdErrPipe
the function is called after execution of command, to write the error output to some output. So, the program already has the output it needs to write.