mirror of
https://github.com/Luzifer/streamdeck.git
synced 2025-01-01 23:51:24 +00:00
39 lines
759 B
Go
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")
|
|
}
|