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 package custom
import ( import (
"XProxy/cmd/common"
log "github.com/sirupsen/logrus" log "github.com/sirupsen/logrus"
"os"
"os/exec"
) )
type Config struct { type Config struct {
@ -10,16 +11,29 @@ type Config struct {
Post []string `yaml:"post" json:"post"` 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) { func RunPreScript(config *Config) {
for _, script := range config.Pre { for _, script := range config.Pre {
log.Infof("Run pre-script command -> %s", script) log.Infof("Run pre-script command -> %s", script)
common.RunCommand("sh", "-c", script) runScript(script)
} }
} }
func RunPostScript(config *Config) { func RunPostScript(config *Config) {
for _, script := range config.Post { for _, script := range config.Post {
log.Infof("Run post-script command -> %s", script) log.Infof("Run post-script command -> %s", script)
common.RunCommand("sh", "-c", script) runScript(script)
} }
} }

Loading…
Cancel
Save