1
0
Fork 0
mirror of https://github.com/Luzifer/streamdeck.git synced 2025-01-01 23:51:24 +00:00
streamdeck/cmd/streamdeck/action_exec.go
Knut Ahlers dcf7241ca5
Fix: Execute command with parent env
Signed-off-by: Knut Ahlers <knut@ahlers.me>
2019-11-21 18:47:40 +01:00

39 lines
759 B
Go

package main
import (
"os"
"os/exec"
"github.com/pkg/errors"
)
func init() {
registerAction("exec", actionExec{})
}
type actionExec struct{}
func (actionExec) Execute(attributes map[string]interface{}) error {
cmd, ok := attributes["command"].([]interface{})
if !ok {
return errors.New("No command supplied")
}
var args []string
for _, c := range cmd {
if v, ok := c.(string); ok {
args = append(args, v)
continue
}
return errors.New("Command conatins non-string argument")
}
command := exec.Command(args[0], args[1:]...)
command.Env = os.Environ()
if err := command.Start(); err != nil {
return errors.Wrap(err, "Unable to start command")
}
return errors.Wrap(command.Process.Release(), "Unable to release process")
}