You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
53 lines
1.5 KiB
53 lines
1.5 KiB
package initFunc |
|
|
|
import ( |
|
"fmt" |
|
"os" |
|
"os/exec" |
|
"syscall" |
|
"time" |
|
) |
|
|
|
// 执行exe 文件,开启视频监控的服务进程 |
|
func RunPiServerExe() { |
|
// 获取当前目录 |
|
dir, _ := os.Getwd() |
|
applicationPath := dir + "/piVideo" |
|
// //切换到目录 |
|
os.Chdir(applicationPath) |
|
//执行exe的路径 |
|
exePath := dir + "/piVideo/piVideo.exe" |
|
fmt.Println("piVide 可执行路径:", exePath) |
|
killPiServerExe("piVideo.exe") //杀 piVideo 进程 |
|
killPiServerExe("RTSPtoWeb.exe") //杀 RRTSPtoWeb 进程 |
|
time.Sleep(3 * time.Second) |
|
cmd := exec.Command(exePath) // 替换为您的可执行文件路径 |
|
// os.Chdir("piVideo") |
|
output, err := cmd.CombinedOutput() |
|
if err != nil { |
|
fmt.Println("执行失败", err.Error(), string(output)) |
|
} else { |
|
fmt.Println("执行成功", string(output)) |
|
} |
|
} |
|
func killPiServerExe(exeName string) { |
|
// 定义要关闭的程序的名称(或路径) |
|
if exeName == "" { |
|
exeName = "piVideo.exe" |
|
} |
|
// 使用exec.Command函数创建一个Cmd结构体,用于执行命令 |
|
cmd := exec.Command("taskkill", "/f", "/im", exeName) |
|
cmd.SysProcAttr = &syscall.SysProcAttr{HideWindow:true} |
|
// 将命令的输出和错误连接到当前进程的标准输出和标准错误 |
|
cmd.Stdout = os.Stdout |
|
cmd.Stderr = os.Stderr |
|
// 执行命令 |
|
err := cmd.Run() |
|
|
|
if err != nil { |
|
// 如果发生错误,输出错误信息 |
|
fmt.Println("可能进程并没有开启/关闭视频监控进程Error:", err) |
|
}else{ |
|
fmt.Println("关闭视频监控进程成功") |
|
} |
|
} |