From 58546c9ead7d4c5ad8ef97d97f848bd88e8e6e5c Mon Sep 17 00:00:00 2001 From: dnomd343 Date: Wed, 31 Aug 2022 13:29:14 +0800 Subject: [PATCH] fix: detach stdout and stderr in script --- cmd/custom/main.go | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/cmd/custom/main.go b/cmd/custom/main.go index fa65275..4aa2022 100644 --- a/cmd/custom/main.go +++ b/cmd/custom/main.go @@ -1,8 +1,9 @@ package custom import ( - "XProxy/cmd/common" log "github.com/sirupsen/logrus" + "os" + "os/exec" ) type Config struct { @@ -10,16 +11,29 @@ type Config struct { Post []string `yaml:"post" json:"post"` } +func runScript(command string) { + log.Debugf("Run script -> %s", command) + cmd := exec.Command("sh", "-c", command) + cmd.Stdout = os.Stdout + cmd.Stderr = os.Stderr + err := cmd.Start() + if err != nil { + log.Warningf("Script `%s` working error", command) + } else { + _ = cmd.Wait() + } +} + func RunPreScript(config *Config) { for _, script := range config.Pre { log.Infof("Run pre-script command -> %s", script) - common.RunCommand("sh", "-c", script) + runScript(script) } } func RunPostScript(config *Config) { for _, script := range config.Post { log.Infof("Run post-script command -> %s", script) - common.RunCommand("sh", "-c", script) + runScript(script) } }