Пример #1
0
// PipeWith functions like Pipe, but runs the first command with stdin as the
// input.
func PipeWith(stdin string, cmds ...Executable) Executable {
	ps := make([]pipe.Pipe, len(cmds)+1)
	ps[0] = pipe.Read(strings.NewReader(stdin))
	for i, c := range cmds {
		ps[i+1] = c.Pipe
	}
	return Executable{pipe.Line(ps...)}
}
Пример #2
0
func (S) TestRead(c *C) {
	p := pipe.Line(
		pipe.Read(bytes.NewBufferString("hello")),
		pipe.Exec("sed", "s/l/k/g"),
	)
	output, err := pipe.Output(p)
	c.Assert(err, IsNil)
	c.Assert(string(output), Equals, "hekko")
}
Пример #3
0
// Read returns an executable that will read from the given reader and use it as
// the Executable's stdout.
func Read(r io.Reader) Executable {
	return Executable{pipe.Read(r)}
}
Пример #4
0
// RunWith executes the command with the given string as standard input, and
// returns stdout and a nil error on success, or stderr and a non-nil error on
// failure.
func (c Executable) RunWith(stdin string) (string, error) {
	out, err := pipe.CombinedOutput(
		pipe.Line(pipe.Read(strings.NewReader(stdin)), c.Pipe),
	)
	return string(out), err
}