mirror of
https://github.com/Luzifer/streamdeck.git
synced 2024-12-21 02:01:24 +00:00
[exec] Add env, attach_stderr / stdout parameters
Signed-off-by: Knut Ahlers <knut@ahlers.me>
This commit is contained in:
parent
4cf347407a
commit
74bd0d7fb4
3 changed files with 25 additions and 2 deletions
|
@ -4,6 +4,7 @@ import (
|
||||||
"os"
|
"os"
|
||||||
"os/exec"
|
"os/exec"
|
||||||
|
|
||||||
|
"github.com/Luzifer/go_helpers/v2/env"
|
||||||
"github.com/pkg/errors"
|
"github.com/pkg/errors"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -28,8 +29,24 @@ func (actionExec) Execute(attributes map[string]interface{}) error {
|
||||||
return errors.New("Command conatins non-string argument")
|
return errors.New("Command conatins non-string argument")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
processEnv := env.ListToMap(os.Environ())
|
||||||
|
|
||||||
|
if e, ok := attributes["env"].(map[string]string); ok {
|
||||||
|
for k, v := range e {
|
||||||
|
processEnv[k] = v
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
command := exec.Command(args[0], args[1:]...)
|
command := exec.Command(args[0], args[1:]...)
|
||||||
command.Env = os.Environ()
|
command.Env = env.MapToList(processEnv)
|
||||||
|
|
||||||
|
if v, ok := attributes["attach_stdout"].(bool); ok && v {
|
||||||
|
command.Stdout = os.Stdout
|
||||||
|
}
|
||||||
|
|
||||||
|
if v, ok := attributes["attach_stderr"].(bool); ok && v {
|
||||||
|
command.Stdout = os.Stderr
|
||||||
|
}
|
||||||
|
|
||||||
if err := command.Start(); err != nil {
|
if err := command.Start(); err != nil {
|
||||||
return errors.Wrap(err, "Unable to start command")
|
return errors.Wrap(err, "Unable to start command")
|
||||||
|
@ -37,7 +54,7 @@ func (actionExec) Execute(attributes map[string]interface{}) error {
|
||||||
|
|
||||||
// If "wait" is set and set to true start command and wait for execution
|
// If "wait" is set and set to true start command and wait for execution
|
||||||
if v, ok := attributes["wait"].(bool); ok && v {
|
if v, ok := attributes["wait"].(bool); ok && v {
|
||||||
return errors.Wrap(command.Wait(), "Unable to execute command")
|
return errors.Wrap(command.Wait(), "Command was not successful")
|
||||||
}
|
}
|
||||||
|
|
||||||
// We don't wait so we release the process and don't care anymore
|
// We don't wait so we release the process and don't care anymore
|
||||||
|
|
|
@ -5,6 +5,7 @@ go 1.13
|
||||||
replace github.com/Luzifer/streamdeck => ../../
|
replace github.com/Luzifer/streamdeck => ../../
|
||||||
|
|
||||||
require (
|
require (
|
||||||
|
github.com/Luzifer/go_helpers/v2 v2.10.0
|
||||||
github.com/Luzifer/rconfig/v2 v2.2.1
|
github.com/Luzifer/rconfig/v2 v2.2.1
|
||||||
github.com/Luzifer/streamdeck v0.0.0-20191122003228-a2f524a6b22c
|
github.com/Luzifer/streamdeck v0.0.0-20191122003228-a2f524a6b22c
|
||||||
github.com/fsnotify/fsnotify v1.4.7
|
github.com/fsnotify/fsnotify v1.4.7
|
||||||
|
|
|
@ -1,3 +1,6 @@
|
||||||
|
github.com/Luzifer/go_helpers v1.4.0 h1:Pmm058SbYewfnpP1CHda/zERoAqYoZFiBHF4l8k03Ko=
|
||||||
|
github.com/Luzifer/go_helpers/v2 v2.10.0 h1:rA3945P6tH1PKRdcVD+nAdAWojfgwX8wQm/jjUNPmfg=
|
||||||
|
github.com/Luzifer/go_helpers/v2 v2.10.0/go.mod h1:ZnWxPjyCdQ4rZP3kNiMSUW/7FigU1X9Rz8XopdJ5ZCU=
|
||||||
github.com/Luzifer/rconfig/v2 v2.2.1 h1:zcDdLQlnlzwcBJ8E0WFzOkQE1pCMn3EbX0dFYkeTczg=
|
github.com/Luzifer/rconfig/v2 v2.2.1 h1:zcDdLQlnlzwcBJ8E0WFzOkQE1pCMn3EbX0dFYkeTczg=
|
||||||
github.com/Luzifer/rconfig/v2 v2.2.1/go.mod h1:OKIX0/JRZrPJ/ZXXWklQEFXA6tBfWaljZbW37w+sqBw=
|
github.com/Luzifer/rconfig/v2 v2.2.1/go.mod h1:OKIX0/JRZrPJ/ZXXWklQEFXA6tBfWaljZbW37w+sqBw=
|
||||||
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
||||||
|
@ -7,10 +10,12 @@ github.com/fsnotify/fsnotify v1.4.7 h1:IXs+QLmnXW2CcXuY+8Mzv/fWEsPGWxqefPtCP5CnV
|
||||||
github.com/fsnotify/fsnotify v1.4.7/go.mod h1:jwhsz4b93w/PPRr/qN1Yymfu8t87LnFCMoQvtojpjFo=
|
github.com/fsnotify/fsnotify v1.4.7/go.mod h1:jwhsz4b93w/PPRr/qN1Yymfu8t87LnFCMoQvtojpjFo=
|
||||||
github.com/golang/freetype v0.0.0-20170609003504-e2365dfdc4a0 h1:DACJavvAHhabrF08vX0COfcOBJRhZ8lUbR+ZWIs0Y5g=
|
github.com/golang/freetype v0.0.0-20170609003504-e2365dfdc4a0 h1:DACJavvAHhabrF08vX0COfcOBJRhZ8lUbR+ZWIs0Y5g=
|
||||||
github.com/golang/freetype v0.0.0-20170609003504-e2365dfdc4a0/go.mod h1:E/TSTwGwJL78qG/PmXZO1EjYhfJinVAhrmmHX6Z8B9k=
|
github.com/golang/freetype v0.0.0-20170609003504-e2365dfdc4a0/go.mod h1:E/TSTwGwJL78qG/PmXZO1EjYhfJinVAhrmmHX6Z8B9k=
|
||||||
|
github.com/inconshreveable/go-update v0.0.0-20160112193335-8152e7eb6ccf/go.mod h1:hyb9oH7vZsitZCiBt0ZvifOrB+qc8PS5IiilCIb87rg=
|
||||||
github.com/konsorten/go-windows-terminal-sequences v1.0.1 h1:mweAR1A6xJ3oS2pRaGiHgQ4OO8tzTaLawm8vnODuwDk=
|
github.com/konsorten/go-windows-terminal-sequences v1.0.1 h1:mweAR1A6xJ3oS2pRaGiHgQ4OO8tzTaLawm8vnODuwDk=
|
||||||
github.com/konsorten/go-windows-terminal-sequences v1.0.1/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ=
|
github.com/konsorten/go-windows-terminal-sequences v1.0.1/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ=
|
||||||
github.com/konsorten/go-windows-terminal-sequences v1.0.2 h1:DB17ag19krx9CFsz4o3enTrPXyIXCl+2iCXH/aMAp9s=
|
github.com/konsorten/go-windows-terminal-sequences v1.0.2 h1:DB17ag19krx9CFsz4o3enTrPXyIXCl+2iCXH/aMAp9s=
|
||||||
github.com/konsorten/go-windows-terminal-sequences v1.0.2/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ=
|
github.com/konsorten/go-windows-terminal-sequences v1.0.2/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ=
|
||||||
|
github.com/leekchan/gtf v0.0.0-20190214083521-5fba33c5b00b/go.mod h1:thNruaSwydMhkQ8dXzapABF9Sc1Tz08ZBcDdgott9RA=
|
||||||
github.com/pkg/errors v0.8.1 h1:iURUrRGxPUNPdy5/HRSm+Yj6okJ6UtLINN0Q9M4+h3I=
|
github.com/pkg/errors v0.8.1 h1:iURUrRGxPUNPdy5/HRSm+Yj6okJ6UtLINN0Q9M4+h3I=
|
||||||
github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
|
github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
|
||||||
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
|
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
|
||||||
|
|
Loading…
Reference in a new issue