1
0
Fork 0
mirror of https://github.com/Luzifer/streamdeck.git synced 2024-12-29 22:21:24 +00:00

Add "exec" action

Signed-off-by: Knut Ahlers <knut@ahlers.me>
This commit is contained in:
Knut Ahlers 2019-11-21 18:38:27 +01:00
parent 81e4f693ae
commit 9ed2e81404
Signed by: luzifer
GPG key ID: DC2729FDD34BE99E

View file

@ -0,0 +1,36 @@
package main
import (
"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:]...)
if err := command.Start(); err != nil {
return errors.Wrap(err, "Unable to start command")
}
return errors.Wrap(command.Process.Release(), "Unable to release process")
}