diff --git a/bees/execbee/execbee.go b/bees/execbee/execbee.go index 58aab256..b347fd72 100644 --- a/bees/execbee/execbee.go +++ b/bees/execbee/execbee.go @@ -18,6 +18,7 @@ * Authors: * Dominik Schmidt * Christian Muehlhaeuser + * Matthias Krauser */ // Package execbee is a Bee that can launch external processes. @@ -25,6 +26,7 @@ package execbee import ( "bufio" + "io" "os/exec" "strings" @@ -45,13 +47,30 @@ func (mod *ExecBee) Action(action bees.Action) []bees.Placeholder { switch action.Name { case "execute": var command string + var stdin string + action.Options.Bind("command", &command) + action.Options.Bind("stdin", &stdin) mod.Logln("Executing locally: ", command) go func() { c := strings.Split(command, " ") cmd := exec.Command(c[0], c[1:]...) + if stdin != "" { + stdinPipe, err := cmd.StdinPipe() + + if err != nil { + mod.LogFatal("Error creating stdinPipe for Cmd", err) + return + } + + go func() { + io.WriteString(stdinPipe, stdin) + stdinPipe.Close() + }() + } + // read and print stdout outReader, err := cmd.StdoutPipe() if err != nil { diff --git a/bees/execbee/execbeefactory.go b/bees/execbee/execbeefactory.go index 11a4fe83..1ea86bc8 100644 --- a/bees/execbee/execbeefactory.go +++ b/bees/execbee/execbeefactory.go @@ -18,6 +18,7 @@ * Authors: * Dominik Schmidt * Christian Muehlhaeuser + * Matthias Krauser */ package execbee @@ -104,6 +105,12 @@ func (factory *ExecBeeFactory) Actions() []bees.ActionDescriptor { Type: "string", Mandatory: true, }, + { + Name: "stdin", + Description: "stdin-Data for the command", + Type: "string", + Mandatory: false, + }, }, }, }