Implement all external commands for Windows
This commit is contained in:
@@ -7,6 +7,7 @@ import (
|
||||
"net"
|
||||
"os"
|
||||
"os/exec"
|
||||
"runtime"
|
||||
"strconv"
|
||||
"strings"
|
||||
"sync/atomic"
|
||||
@@ -229,7 +230,13 @@ var errRunRecord = errors.New("record")
|
||||
func (c *client) run() {
|
||||
var onConnectCmd *exec.Cmd
|
||||
if c.p.conf.RunOnConnect != "" {
|
||||
onConnectCmd = exec.Command("/bin/sh", "-c", c.p.conf.RunOnConnect)
|
||||
var substitutedCommand = strings.ReplaceAll(c.p.conf.RunOnConnect, "$RTSP_SERVER_PATH", c.path.name)
|
||||
if runtime.GOOS == "windows" {
|
||||
var command = strings.Fields(substitutedCommand)
|
||||
onConnectCmd = exec.Command(command[0], command[1:]...)
|
||||
} else {
|
||||
onConnectCmd = exec.Command("/bin/sh", "-c", substitutedCommand)
|
||||
}
|
||||
onConnectCmd.Stdout = os.Stdout
|
||||
onConnectCmd.Stderr = os.Stderr
|
||||
err := onConnectCmd.Start()
|
||||
@@ -926,10 +933,13 @@ func (c *client) runPlay() bool {
|
||||
|
||||
var onReadCmd *exec.Cmd
|
||||
if c.path.confp.RunOnRead != "" {
|
||||
onReadCmd = exec.Command("/bin/sh", "-c", c.path.confp.RunOnRead)
|
||||
onReadCmd.Env = append(os.Environ(),
|
||||
"RTSP_SERVER_PATH="+c.path.name,
|
||||
)
|
||||
var substitutedCommand = strings.ReplaceAll(c.path.confp.RunOnRead, "$RTSP_SERVER_PATH", c.path.name)
|
||||
if runtime.GOOS == "windows" {
|
||||
var command = strings.Fields(substitutedCommand)
|
||||
onReadCmd = exec.Command(command[0], command[1:]...)
|
||||
} else {
|
||||
onReadCmd = exec.Command("/bin/sh", "-c", substitutedCommand)
|
||||
}
|
||||
onReadCmd.Stdout = os.Stdout
|
||||
onReadCmd.Stderr = os.Stderr
|
||||
err := onReadCmd.Start()
|
||||
@@ -1074,10 +1084,13 @@ func (c *client) runRecord() bool {
|
||||
|
||||
var onPublishCmd *exec.Cmd
|
||||
if c.path.confp.RunOnPublish != "" {
|
||||
onPublishCmd = exec.Command("/bin/sh", "-c", c.path.confp.RunOnPublish)
|
||||
onPublishCmd.Env = append(os.Environ(),
|
||||
"RTSP_SERVER_PATH="+c.path.name,
|
||||
)
|
||||
var substitutedCommand = strings.ReplaceAll(c.path.confp.RunOnPublish, "$RTSP_SERVER_PATH", c.path.name)
|
||||
if runtime.GOOS == "windows" {
|
||||
var command = strings.Fields(substitutedCommand)
|
||||
onPublishCmd = exec.Command(command[0], command[1:]...)
|
||||
} else {
|
||||
onPublishCmd = exec.Command("/bin/sh", "-c", substitutedCommand)
|
||||
}
|
||||
onPublishCmd.Stdout = os.Stdout
|
||||
onPublishCmd.Stderr = os.Stderr
|
||||
err := onPublishCmd.Start()
|
||||
|
||||
@@ -4,6 +4,8 @@ import (
|
||||
"fmt"
|
||||
"os"
|
||||
"os/exec"
|
||||
"runtime"
|
||||
"strings"
|
||||
"time"
|
||||
)
|
||||
|
||||
@@ -62,11 +64,13 @@ func (pa *path) onInit() {
|
||||
|
||||
if pa.confp.RunOnInit != "" {
|
||||
pa.log("starting on init command")
|
||||
|
||||
pa.onInitCmd = exec.Command("/bin/sh", "-c", pa.confp.RunOnInit)
|
||||
pa.onInitCmd.Env = append(os.Environ(),
|
||||
"RTSP_SERVER_PATH="+pa.name,
|
||||
)
|
||||
var substitutedCommand = strings.ReplaceAll(pa.confp.RunOnInit, "$RTSP_SERVER_PATH", pa.name)
|
||||
if runtime.GOOS == "windows" {
|
||||
var command = strings.Fields(substitutedCommand)
|
||||
pa.onInitCmd = exec.Command(command[0], command[1:]...)
|
||||
} else {
|
||||
pa.onInitCmd = exec.Command("/bin/sh", "-c", substitutedCommand)
|
||||
}
|
||||
pa.onInitCmd.Stdout = os.Stdout
|
||||
pa.onInitCmd.Stderr = os.Stderr
|
||||
err := pa.onInitCmd.Start()
|
||||
@@ -233,10 +237,13 @@ func (pa *path) onDescribe(client *client) {
|
||||
pa.log("starting on demand command")
|
||||
|
||||
pa.lastDescribeActivation = time.Now()
|
||||
pa.onDemandCmd = exec.Command("/bin/sh", "-c", pa.confp.RunOnDemand)
|
||||
pa.onDemandCmd.Env = append(os.Environ(),
|
||||
"RTSP_SERVER_PATH="+pa.name,
|
||||
)
|
||||
var substitutedCommand = strings.ReplaceAll(pa.confp.RunOnDemand, "$RTSP_SERVER_PATH", pa.name)
|
||||
if runtime.GOOS == "windows" {
|
||||
var command = strings.Fields(substitutedCommand)
|
||||
pa.onDemandCmd = exec.Command(command[0], command[1:]...)
|
||||
} else {
|
||||
pa.onDemandCmd = exec.Command("/bin/sh", "-c", substitutedCommand)
|
||||
}
|
||||
pa.onDemandCmd.Stdout = os.Stdout
|
||||
pa.onDemandCmd.Stderr = os.Stderr
|
||||
err := pa.onDemandCmd.Start()
|
||||
|
||||
Reference in New Issue
Block a user