Browse Source

fix: detach stdout and stderr in script

v1.x.x
dnomd343 2 years ago
parent
commit
58546c9ead
  1. 20
      cmd/custom/main.go

20
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)
}
}

Loading…
Cancel
Save