2020-11-08 22:12:43 +00:00
|
|
|
// +build windows
|
|
|
|
|
|
|
|
package externalcmd
|
|
|
|
|
|
|
|
import (
|
|
|
|
"os"
|
|
|
|
"os/exec"
|
|
|
|
"strings"
|
|
|
|
|
|
|
|
"github.com/kballard/go-shellquote"
|
|
|
|
)
|
|
|
|
|
2020-11-21 12:35:33 +00:00
|
|
|
func (e *Cmd) runInner() bool {
|
2020-11-08 22:12:43 +00:00
|
|
|
// on Windows the shell is not used and command is started directly
|
|
|
|
// variables are replaced manually in order to guarantee compatibility
|
|
|
|
// with Linux commands
|
|
|
|
tmp := strings.ReplaceAll(e.cmdstr, "$RTSP_PATH", e.env.Path)
|
|
|
|
tmp = strings.ReplaceAll(tmp, "$RTSP_PORT", e.env.Port)
|
|
|
|
parts, err := shellquote.Split(tmp)
|
|
|
|
if err != nil {
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
|
|
|
|
cmd := exec.Command(parts[0], parts[1:]...)
|
|
|
|
|
|
|
|
cmd.Env = append(os.Environ(),
|
|
|
|
"RTSP_PATH="+e.env.Path,
|
|
|
|
"RTSP_PORT="+e.env.Port,
|
|
|
|
)
|
|
|
|
|
|
|
|
cmd.Stdout = os.Stdout
|
|
|
|
cmd.Stderr = os.Stderr
|
|
|
|
|
2020-11-11 09:56:18 +00:00
|
|
|
err = cmd.Start()
|
2020-11-08 22:12:43 +00:00
|
|
|
if err != nil {
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
|
|
|
|
cmdDone := make(chan struct{})
|
|
|
|
go func() {
|
|
|
|
defer close(cmdDone)
|
|
|
|
cmd.Wait()
|
|
|
|
}()
|
|
|
|
|
|
|
|
select {
|
|
|
|
case <-e.terminate:
|
|
|
|
// on Windows it's not possible to send os.Interrupt to a process
|
|
|
|
// Kill() is the only supported way
|
|
|
|
cmd.Process.Kill()
|
|
|
|
<-cmdDone
|
|
|
|
return false
|
|
|
|
|
|
|
|
case <-cmdDone:
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
}
|