1
0

exec.go 706 B

12345678910111213141516171819202122232425262728293031
  1. package nginx
  2. import (
  3. "context"
  4. "os/exec"
  5. "github.com/0xJacky/Nginx-UI/internal/docker"
  6. "github.com/0xJacky/Nginx-UI/settings"
  7. )
  8. func execShell(cmd string) (stdOut string, stdErr error) {
  9. return execCommand("/bin/sh", "-c", cmd)
  10. }
  11. func execCommand(name string, cmd ...string) (stdOut string, stdErr error) {
  12. switch settings.NginxSettings.RunningInAnotherContainer() {
  13. case true:
  14. cmd = append([]string{name}, cmd...)
  15. stdOut, stdErr = docker.Exec(context.Background(), cmd)
  16. case false:
  17. execCmd := exec.Command(name, cmd...)
  18. // fix #1046
  19. execCmd.Dir = getNginxExeDir()
  20. bytes, err := execCmd.CombinedOutput()
  21. stdOut = string(bytes)
  22. if err != nil {
  23. stdErr = err
  24. }
  25. }
  26. return
  27. }