mirror of
https://github.com/Luzifer/streamdeck.git
synced 2024-12-20 17:51:21 +00:00
Add "exec" action
Signed-off-by: Knut Ahlers <knut@ahlers.me>
This commit is contained in:
parent
81e4f693ae
commit
9ed2e81404
1 changed files with 36 additions and 0 deletions
36
cmd/streamdeck/action_exec.go
Normal file
36
cmd/streamdeck/action_exec.go
Normal 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")
|
||||||
|
}
|
Loading…
Reference in a new issue