Documentation ¶
Overview ¶
Package cmd provides helper functions for working with the os/exec library.
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Output ¶
Output executes the command & returns stdout. Stderr and error exit codes are reported as the returned error.
Example ¶
tempdir, _ := ioutil.TempDir("", "example-output") defer os.RemoveAll(tempdir) os.MkdirAll(filepath.Join(tempdir, "sub1"), 0744) os.MkdirAll(filepath.Join(tempdir, "sub2"), 0744) out, _ := Output(exec.Command("ls", tempdir)) for _, k := range out { fmt.Println(k) }
Output: sub1 sub2
func PipeWith ¶
PipeWith executes the command & sends the provided event handler the stdout io.Reader. Errors returned from the event handler are forwarded on. Stderr and error exit codes are reported as the returned error.
Example ¶
tempdir, _ := ioutil.TempDir("", "example-pipewith") defer os.RemoveAll(tempdir) os.MkdirAll(filepath.Join(tempdir, "sub1"), 0744) os.MkdirAll(filepath.Join(tempdir, "sub2"), 0744) PipeWith(exec.Command("ls", tempdir), func(stdout io.Reader) error { scanner := bufio.NewScanner(stdout) for scanner.Scan() { fmt.Println(scanner.Text()) } return nil })
Output: sub1 sub2
func Run ¶
Run executes the command & throws away stdout. Stderr and error exit codes are reported as the returned error.
Example ¶
tempdir, _ := ioutil.TempDir("", "example-run") defer os.RemoveAll(tempdir) os.MkdirAll(filepath.Join(tempdir, "sub1"), 0744) os.MkdirAll(filepath.Join(tempdir, "sub2"), 0744) if runErr := Run(exec.Command("ls", tempdir)); runErr != nil { fmt.Printf("Got error %v", runErr) }
Output:
Types ¶
Click to show internal directories.
Click to hide internal directories.