Drilling down farther for the heck of it
os/exec/exec.go
func (c *Cmd) Output() ([]byte, error) { if c.Stdout != nil {
return nil, errors.New("exec: Stdout already set")
}
var stdout bytes.Buffer
c.Stdout = &stdout
captureErr := c.Stderr == nil
if captureErr {
c.Stderr = &prefixSuffixSaver{N: 32 << 10}
}
err := c.Run()
if err != nil && captureErr {
if ee, ok := err.(*ExitError); ok {
ee.Stderr = c.Stderr.(*prefixSuffixSaver).Bytes()
}
}
return stdout.Bytes(), err
}
stdout.Bytes() = bytes.Buffer.Bytes()
bytes/buffer.go
// Bytes returns a slice of length b.Len() holding the unread portion of the
buffer.// The slice is valid for use only until the next buffer modification
(that is,// only until the next call to a method like Read, Write, Reset, or
Truncate).// The slice aliases the buffer content at least until the next
buffer modification,// so immediate changes to the slice will affect the result
of future reads.
func (b *Buffer) Bytes() []byte { return b.buf[b.off:] }
// A Buffer is a variable-sized buffer of bytes with Read and Write methods.//
The zero value for Buffer is an empty buffer ready to use.
type Buffer struct {
buf []byte // contents are the bytes buf[off : len(buf)]
off int // read at &buf[off], write at &buf[len(buf)]
bootstrap [64]byte // memory to hold first slice; helps small buffers
avoid allocation.
lastRead readOp // last read operation, so that Unread* can work
correctly.
// FIXME: it would be advisable to align Buffer to cachelines to avoid
false
// sharing.
}
I am still not sure where the "10" or '\n' came from, but I know enough to get
the program working. I am really enjoying getting to learn this language and
excited for all that I can get it to do, even if it comes with the expected
frustrations and head against wall banging.
--
You received this message because you are subscribed to the Google Groups
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
For more options, visit https://groups.google.com/d/optout.