Documentation ¶
Index ¶
- Constants
- type PipedExec
- func (pe *PipedExec) Command(name string, args ...string) *PipedExec
- func (pe *PipedExec) GetCmd(idx int) *exec.Cmd
- func (pe *PipedExec) Run(out io.Writer, err io.Writer) error
- func (pe *PipedExec) RunToStrings() (stdout string, stderr string, err error)
- func (pe *PipedExec) Start(out io.Writer, err io.Writer) error
- func (pe *PipedExec) Wait() error
- func (pe *PipedExec) WorkingDir(wd string) *PipedExec
Examples ¶
Constants ¶
View Source
const ( StderrRedirectNone = iota StderrRedirectStdout StderrRedirectNull )
Stderr redirection
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type PipedExec ¶
type PipedExec struct {
// contains filtered or unexported fields
}
PipedExec allows to execute commands in pipe
func (*PipedExec) Run ¶
Run starts the pipe
Example ¶
Run a command and use os.Stdout, os.Stderr
package main import ( "fmt" "os" "github.com/voedger/voedger/pkg/goutils/exec" ) func main() { err := new(exec.PipedExec). Command("echo", "Run"). Run(os.Stdout, os.Stderr) if err != nil { fmt.Println("exec.PipedExec failed:", err) } }
Output: Run
func (*PipedExec) RunToStrings ¶
RunToStrings runs the pipe and saves outputs to strings
Example ¶
Run a command and capture its output to strings
package main import ( "fmt" "strings" "github.com/voedger/voedger/pkg/goutils/exec" ) func main() { stdout, stderr, err := new(exec.PipedExec). Command("echo", "RunToStrings"). RunToStrings() if err != nil { fmt.Println("exec.PipedExec failed:", err, stderr) } fmt.Println(strings.TrimSpace(stdout)) }
Output: RunToStrings
Example (Pipe) ¶
printf "1\n2\n3" | grep 2
package main import ( "fmt" "strings" "github.com/voedger/voedger/pkg/goutils/exec" ) func main() { stdout, stderr, err := new(exec.PipedExec). Command("printf", `1\n2\n3`). Command("grep", "2"). RunToStrings() if err != nil { fmt.Println("exec.PipedExec failed:", err, stderr) } fmt.Println(strings.TrimSpace(stdout)) }
Output: 2
func (*PipedExec) WorkingDir ¶
WorkingDir sets working directory for the last command
Click to show internal directories.
Click to hide internal directories.