mediamtx/internal/externalcmd/cmd_unix.go

42 lines
570 B
Go
Raw Normal View History

// +build !windows
package externalcmd
import (
"os"
"os/exec"
)
2020-11-21 12:35:33 +00:00
func (e *Cmd) runInner() bool {
cmd := exec.Command("/bin/sh", "-c", "exec "+e.cmdstr)
cmd.Env = append(os.Environ(),
"RTSP_PATH="+e.env.Path,
"RTSP_PORT="+e.env.Port,
)
cmd.Stdout = os.Stdout
cmd.Stderr = os.Stderr
err := cmd.Start()
if err != nil {
return true
}
cmdDone := make(chan struct{})
go func() {
defer close(cmdDone)
cmd.Wait()
}()
select {
case <-e.terminate:
cmd.Process.Signal(os.Interrupt)
<-cmdDone
return false
case <-cmdDone:
return true
}
}