From da632565d570392b40fa0b2598d0ed81838c7d33 Mon Sep 17 00:00:00 2001 From: josc146 Date: Tue, 12 Dec 2023 23:48:32 +0800 Subject: [PATCH] fix windows cmd waiting --- backend-golang/file.go | 6 +++++- backend-golang/utils.go | 11 +++++------ 2 files changed, 10 insertions(+), 7 deletions(-) diff --git a/backend-golang/file.go b/backend-golang/file.go index d3a69f2..63fb4ab 100644 --- a/backend-golang/file.go +++ b/backend-golang/file.go @@ -204,6 +204,10 @@ func (a *App) OpenFileFolder(path string, relative bool) error { } func (a *App) StartFile(path string) error { - _, err := CmdHelper(true, path) + cmd, err := CmdHelper(true, path) + if err != nil { + return err + } + err = cmd.Start() return err } diff --git a/backend-golang/utils.go b/backend-golang/utils.go index 65f5d8f..731de3a 100644 --- a/backend-golang/utils.go +++ b/backend-golang/utils.go @@ -44,21 +44,20 @@ func CmdHelper(hideWindow bool, args ...string) (*exec.Cmd, error) { cmd := exec.Command(cmdHelper, args...) cmd.SysProcAttr = &syscall.SysProcAttr{} //go:custom_build windows cmd.SysProcAttr.HideWindow = hideWindow - err = cmd.Start() - if err != nil { - return nil, err - } return cmd, nil } func Cmd(args ...string) (string, error) { switch platform := runtime.GOOS; platform { case "windows": - cmd, err := CmdHelper(false, args...) + cmd, err := CmdHelper(true, args...) + if err != nil { + return "", err + } + _, err = cmd.CombinedOutput() if err != nil { return "", err } - cmd.Wait() return "", nil case "darwin": ex, err := os.Executable()