Documentation
¶
Index ¶
Constants ¶
View Source
const ErrCodeNil int = 1000
Variables ¶
This section is empty.
Functions ¶
func Run ¶
Run strings together the given exec.Cmd commands in a similar fashion to the
Unix pipeline. Each command's standard output is connected to the standard input of the next command, and the output of the final command in the pipeline is returned, along with the collected standard error of all cmds and the first error found (if any). To provide input to the pipeline, assign an io.Reader to the first's Stdin. Pipeline exit code: if all cmds start ok and exit zero, finErr=nil, otherwise finErr assigned to a pipeline.Error struct, which Code is value of the last (rightmost) command to exit with a non-zero status. like Bash set -o pipefail. Examples: 1: stdout, stderr, err := pipeline.Run(&os.Stderr, exec.Command("ls", "-alh")) if err == nil { fmt.Println("stdout:", stdout.String()) } else { fmt.Printf("exit_code: %d\n", err.(*pipeline.Error).Code) fmt.Printf("error: %v", err.(*pipeline.Error).Err) } 2: stdout, _, err := pipeline.Run(&stderr, exec.Command("ls", "-alh"), exec.Command("cat")) 3: cmd := exec.Command("cat") cmd.Stdin = os.Stdin // to read input from user stdout, _, _ := pipeline.Run(&cmd, exec.Command("tr", "a-z", "A-Z"))
Types ¶
Click to show internal directories.
Click to hide internal directories.