mirror of
https://github.com/schollz/cowyo.git
synced 2023-08-10 21:13:00 +03:00
29 lines
715 B
Go
29 lines
715 B
Go
package pipeutil
|
|
|
|
import "gopkg.in/pipe.v2"
|
|
|
|
// OutputDir is identical to pipe.Output, except it sets the starting dir.
|
|
func OutputDir(p pipe.Pipe, dir string) ([]byte, error) {
|
|
outb := &pipe.OutputBuffer{}
|
|
s := pipe.NewState(outb, nil)
|
|
s.Dir = dir
|
|
err := p(s)
|
|
if err == nil {
|
|
err = s.RunTasks()
|
|
}
|
|
return outb.Bytes(), err
|
|
}
|
|
|
|
// DividedOutputDir is identical to pipe.DividedOutput, except it sets the starting dir.
|
|
func DividedOutputDir(p pipe.Pipe, dir string) (stdout []byte, stderr []byte, err error) {
|
|
outb := &pipe.OutputBuffer{}
|
|
errb := &pipe.OutputBuffer{}
|
|
s := pipe.NewState(outb, errb)
|
|
s.Dir = dir
|
|
err = p(s)
|
|
if err == nil {
|
|
err = s.RunTasks()
|
|
}
|
|
return outb.Bytes(), errb.Bytes(), err
|
|
}
|