From 81f6541f425e36e09c258939a53b04be3374c723 Mon Sep 17 00:00:00 2001 From: aler9 <46489434+aler9@users.noreply.github.com> Date: Thu, 8 Oct 2020 22:44:47 +0200 Subject: [PATCH] fix killing of external commands on Windows (#97) --- externalcmd.go | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/externalcmd.go b/externalcmd.go index 660d05d6..1d628ced 100644 --- a/externalcmd.go +++ b/externalcmd.go @@ -14,7 +14,7 @@ type externalCmd struct { func startExternalCommand(cmdstr string, pathName string) (*externalCmd, error) { var cmd *exec.Cmd if runtime.GOOS == "windows" { - // in Windows the shell is not used and command is started directly + // on Windows the shell is not used and command is started directly // variables are replaced manually in order to allow // compatibility with linux commands cmdstr = strings.ReplaceAll(cmdstr, "$RTSP_SERVER_PATH", pathName) @@ -44,6 +44,12 @@ func startExternalCommand(cmdstr string, pathName string) (*externalCmd, error) } func (e *externalCmd) close() { - e.cmd.Process.Signal(os.Interrupt) + // on Windows it's not possible to send os.Interrupt to a process + // Kill() is the only supported way + if runtime.GOOS == "windows" { + e.cmd.Process.Kill() + } else { + e.cmd.Process.Signal(os.Interrupt) + } e.cmd.Wait() }