|
@@ -30,21 +30,46 @@ public class CmdUtils {
|
|
* 调用算法 xx.sh 脚本
|
|
* 调用算法 xx.sh 脚本
|
|
* @param command
|
|
* @param command
|
|
*/
|
|
*/
|
|
- public static void callSh(String command){
|
|
|
|
- log.info("cmd: {}", command);
|
|
|
|
|
|
+// public static void callSh(String command, Integer lineSize){
|
|
|
|
+// log.info("cmd: {}", command);
|
|
|
|
+// try {
|
|
|
|
+// String[] cmd = new String[]{"/bin/sh", "-c", command};
|
|
|
|
+// Process process = Runtime.getRuntime().exec(cmd);
|
|
|
|
+// StreamGobbler errorGobbler = new StreamGobbler(process.getErrorStream(), "ERROR");
|
|
|
|
+// errorGobbler.start();
|
|
|
|
+// StreamGobbler outGobbler = new StreamGobbler(process.getInputStream(), "STDOUT");
|
|
|
|
+// outGobbler.start();
|
|
|
|
+// process.waitFor();
|
|
|
|
+// } catch (Exception e) {
|
|
|
|
+// e.printStackTrace();
|
|
|
|
+// }
|
|
|
|
+// }
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ *
|
|
|
|
+ * @param command 命令
|
|
|
|
+ * @param lineSize 日志输出行数 ,可以为null
|
|
|
|
+ */
|
|
|
|
+ public static void callShLine(String command, Integer lineSize){
|
|
|
|
+ log.info("cmd: " + command);
|
|
try {
|
|
try {
|
|
String[] cmd = new String[]{"/bin/sh", "-c", command};
|
|
String[] cmd = new String[]{"/bin/sh", "-c", command};
|
|
Process process = Runtime.getRuntime().exec(cmd);
|
|
Process process = Runtime.getRuntime().exec(cmd);
|
|
- StreamGobbler errorGobbler = new StreamGobbler(process.getErrorStream(), "ERROR");
|
|
|
|
|
|
+ log.info("开始运行");
|
|
|
|
+ StreamGobblerLine errorGobbler = new StreamGobblerLine(process.getErrorStream(), "ERROR");
|
|
errorGobbler.start();
|
|
errorGobbler.start();
|
|
- StreamGobbler outGobbler = new StreamGobbler(process.getInputStream(), "STDOUT");
|
|
|
|
|
|
+ // 200行打印一次日志
|
|
|
|
+ StreamGobblerLine outGobbler = new StreamGobblerLine(process.getInputStream(), "STDOUT", lineSize);
|
|
outGobbler.start();
|
|
outGobbler.start();
|
|
process.waitFor();
|
|
process.waitFor();
|
|
} catch (Exception e) {
|
|
} catch (Exception e) {
|
|
e.printStackTrace();
|
|
e.printStackTrace();
|
|
}
|
|
}
|
|
|
|
+
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
+
|
|
|
|
+
|
|
}
|
|
}
|