| | |
| | | @Value("${mediamtx.host}") |
| | | String mediamtxHost; |
| | | |
| | | @Async |
| | | @PostConstruct |
| | | public void initMediaMtx() { |
| | | if (Platform.isWindows()) { |
| | | String exePath = System.getProperty("user.dir") + File.separator + "lib" + File.separator + "mediamtx" + File.separator + "mediamtx.exe"; |
| | | String ymlPath = System.getProperty("user.dir") + File.separator + "lib" + File.separator + "mediamtx" + File.separator + "mediamtx.yml"; |
| | | try { |
| | | // 构建启动命令,使用cmd /c start命令来启动可执行程序并显示命令提示符窗口 |
| | | String[] cmd = {"cmd", "/c", "start", exePath}; |
| | | |
| | | String[] cmd = {"cmd", "/c", "start", exePath,ymlPath}; |
| | | ProcessBuilder processBuilder = new ProcessBuilder(cmd); |
| | | processBuilder.redirectErrorStream(true); // 将错误输出重定向到标准输出 |
| | | |
| | | Process process = processBuilder.start(); |
| | | |
| | | // 如果你想等待程序完成 |
| | | int exitCode = process.waitFor(); |
| | | System.out.println("程序退出代码: " + exitCode); |
| | | } catch (IOException | InterruptedException e) { |
| | | e.printStackTrace(); |
| | | } |