From a963836e751c1da2b7df9f447da9d0aa4a6e447a Mon Sep 17 00:00:00 2001 From: Lea Anthony Date: Tue, 26 Oct 2021 19:20:39 +1100 Subject: [PATCH] [v2] fix: check process exists before killing --- v2/cmd/wails/internal/commands/dev/dev.go | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/v2/cmd/wails/internal/commands/dev/dev.go b/v2/cmd/wails/internal/commands/dev/dev.go index 3bc7f0bd1..1182daf26 100644 --- a/v2/cmd/wails/internal/commands/dev/dev.go +++ b/v2/cmd/wails/internal/commands/dev/dev.go @@ -389,13 +389,15 @@ func runFrontendDevCommand(cwd string, devCommand string, wg *sync.WaitGroup) fu if runtime.GOOS == "windows" { // Credit: https://stackoverflow.com/a/44551450 // For whatever reason, killing an npm script on windows just doesn't exit properly with cancel - kill := exec.Command("TASKKILL", "/T", "/F", "/PID", strconv.Itoa(cmd.Process.Pid)) - kill.Stderr = os.Stderr - kill.Stdout = os.Stdout - err := kill.Run() - if err != nil { - if err.Error() != "exit status 1" { - LogRed("Error from '%s': %s", devCommand, err.Error()) + if cmd != nil && cmd.Process != nil { + kill := exec.Command("TASKKILL", "/T", "/F", "/PID", strconv.Itoa(cmd.Process.Pid)) + kill.Stderr = os.Stderr + kill.Stdout = os.Stdout + err := kill.Run() + if err != nil { + if err.Error() != "exit status 1" { + LogRed("Error from '%s': %s", devCommand, err.Error()) + } } } } else {