‘liusuyi’
2023-07-27 e279e456850734349842edd8ce52dc16fc5cdea7
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
package com.ruoyi.media.service.impl;
 
import com.sun.jna.Platform;
import org.springframework.stereotype.Component;
 
import javax.annotation.PostConstruct;
import java.io.File;
import java.io.IOException;
 
/**
 * @Description:
 * @ClassName: webrtcService
 * @Author: 刘苏义
 * @Date: 2023年07月26日13:43:07
 * @Version: 1.0
 **/
@Component
public class webrtcService {
    @PostConstruct
    public void init() {
        if (Platform.isWindows()) {
            String exePath = System.getProperty("user.dir") + File.separator + "lib" + File.separator + "webrtc" + File.separator + "setup.bat";
 
            try {
                // 构建启动命令,使用cmd /c start命令来启动可执行程序并显示命令提示符窗口
                String[] cmd = {"cmd", "/c", "start", exePath};
                ProcessBuilder processBuilder = new ProcessBuilder(cmd);
                processBuilder.redirectErrorStream(true); // 将错误输出重定向到标准输出
                Process process = processBuilder.start();
                // 如果你想等待程序完成
                int exitCode = process.waitFor();
            } catch (IOException | InterruptedException e) {
                e.printStackTrace();
            }
        }
    }
}