一键打包生成oem项目exe
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.
 
 
 
 
 

48 lines
1.3 KiB

package initFunc
import (
"fmt"
"os"
"os/exec"
"time"
)
// 执行exe 文件,开启视频监控的服务进程
func RunPiServerExe() {
// 获取当前目录
dir, _ := os.Getwd()
applicationPath := dir + "/frontend/public/piServer"
//切换到目录
os.Chdir(applicationPath)
//执行exe的路径
exePath := dir + "/frontend/public/piVideo/piVideo.exe"
killPiServerExe()
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 := "piVideo.exe"
// 使用exec.Command函数创建一个Cmd结构体,用于执行命令
cmd := exec.Command("taskkill", "/f", "/im", exeName)
// 将命令的输出和错误连接到当前进程的标准输出和标准错误
cmd.Stdout = os.Stdout
cmd.Stderr = os.Stderr
// 执行命令
err := cmd.Run()
if err != nil {
// 如果发生错误,输出错误信息
fmt.Println("可能进程并没有开启/关闭视频监控进程Error:", err)
}else{
fmt.Println("关闭视频监控进程成功")
}
}