Documentation
¶
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Cmd ¶
type Cmd struct {
// contains filtered or unexported fields
}
Cmd is a wrapper arround exec.Cmd. Mainly used to execute command asynchronously with/or without output stream.
func (*Cmd) Run ¶
Run runs the command. if streamOutput is true, it will spin two goroutine responsible of streaming the stdout and stderr
Example (WithNoStream) ¶
package main import ( "fmt" "os/exec" "github.com/aws-controllers-k8s/dev-tools/pkg/asyncexec" ) func main() { cmd := asyncexec.New(exec.Command("echo", "Hello ACK"), 16) cmd.Run() cmd.Wait() fmt.Println(cmd.ExitCode()) }
Output: 0
Example (WithStream) ¶
package main import ( "fmt" "os/exec" "github.com/aws-controllers-k8s/dev-tools/pkg/asyncexec" ) func main() { cmd := asyncexec.New(exec.Command("echo", "Hello ACK"), 16) cmd.Run() done := make(chan struct{}) go func() { for b := range cmd.StdoutStream() { fmt.Println(string(b)) } done <- struct{}{} }() go func() { for b := range cmd.StderrStream() { fmt.Println(string(b)) } done <- struct{}{} }() defer func() { _, _ = <-done, <-done }() cmd.Wait() }
Output: Hello ACK
func (*Cmd) StderrStream ¶
StderrStream returns a channel streaming the command Stderr.
func (*Cmd) StdoutStream ¶
StdoutStream returns a channel streaming the command Stdout.
Click to show internal directories.
Click to hide internal directories.