Ejemplo n.º 1
0
func (S) TestLine(c *C) {
	p := pipe.Line(
		pipe.Exec("/bin/sh", "-c", "echo out1; echo err1 1>&2; echo out2; echo err2 1>&2"),
		pipe.Exec("sed", `s/\(...\)\([12]\)/\1-\2/`),
	)
	output, err := pipe.CombinedOutput(p)
	c.Assert(err, IsNil)
	c.Assert(string(output), Equals, "err1\nerr2\nout-1\nout-2\n")
}
Ejemplo n.º 2
0
func (S) TestScriptCombinedOutput(c *C) {
	p := pipe.Script(
		pipe.System("echo out1; echo err1 1>&2; echo out2; echo err2 1>&2"),
		pipe.System("echo out3; echo err3 1>&2; echo out4; echo err4 1>&2"),
	)
	output, err := pipe.CombinedOutput(p)
	c.Assert(err, IsNil)
	c.Assert(string(output), Equals, "out1\nerr1\nout2\nerr2\nout3\nerr3\nout4\nerr4\n")
}
Ejemplo n.º 3
0
Archivo: sh.go Proyecto: simudream/sh-2
// Run executes the command and returns the combined stdout and stderr, and the
// error if any.
func (c Executable) Run() (string, error) {
	out, err := pipe.CombinedOutput(c.Pipe)
	return string(out), err
}
Ejemplo n.º 4
0
Archivo: sh.go Proyecto: simudream/sh-2
// 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
}
Ejemplo n.º 5
0
func (S) TestExecCombinedOutput(c *C) {
	p := pipe.Exec("/bin/sh", "-c", "echo out1; echo err1 1>&2; echo out2; echo err2 1>&2")
	output, err := pipe.CombinedOutput(p)
	c.Assert(err, IsNil)
	c.Assert(string(output), Equals, "out1\nerr1\nout2\nerr2\n")
}