//远程数据调用 现在是基于shell脚本调用 public String Commandexce(String shellPathName,String runDate){ //String shellScriptPath = "/path/to/your/shellscript.sh"; // 替换为你的Shell脚本路径 //List<String> command = List.of("/bin/sh", shellScriptPath); try { ProcessBuilder processBuilder = new ProcessBuilder(); processBuilder.command("/bin/sh", "-c", shellPathName,runDate); processBuilder.redirectErrorStream(true); // 合并错误和输出流 Process process = processBuilder.start();//启动脚本 // 读取Shell脚本的输出信息和错误信息 BufferedReader reader = new BufferedReader(new InputStreamReader(process.getInputStream())); String line; while ((line = reader.readLine()) != null) { System.out.println(line); } int exitCode = process.waitFor(); // 等待Shell脚本执行完成 if (exitCode != 0) { System.out.println("Shell script execution failed with exit code: " + exitCode); } reader.close(); } catch (Exception e){ e.printStackTrace(); } return null; }
调用 shell或者bat,py脚本 java
最新推荐文章于 2024-08-23 15:54:50 发布