|
@@ -35,59 +35,6 @@ public class CmdUtils {
|
|
|
|
|
|
|
|
|
|
|
|
- /**
|
|
|
- * 命令运行结果 1:失败, 0:成功
|
|
|
- * @return
|
|
|
- * @throws IOException
|
|
|
- * @throws InterruptedException
|
|
|
- */
|
|
|
- public static int cmdPano(String command) throws IOException, InterruptedException {
|
|
|
- log.info("cmd: {}", command);
|
|
|
-// String[] cmd = new String[]{"/bin/sh", "-c", command};
|
|
|
-// Process exec = Runtime.getRuntime().exec(cmd);
|
|
|
-
|
|
|
- // 使用 bin/sh 这个方法会报错
|
|
|
- Process exec = RuntimeUtil.exec(command);
|
|
|
-
|
|
|
- BufferedReader br = new BufferedReader(new InputStreamReader(exec.getInputStream()));
|
|
|
- BufferedReader errorBuf = new BufferedReader(new InputStreamReader(exec.getErrorStream()));
|
|
|
-
|
|
|
- String errorLine;
|
|
|
- while ((errorLine = errorBuf.readLine()) != null) {
|
|
|
- log.error("errorLine: {}", errorLine);
|
|
|
- }
|
|
|
-
|
|
|
- // success ,没有获取到信息
|
|
|
- String line;
|
|
|
- int i = 1;
|
|
|
- while ((line = br.readLine()) != null) {
|
|
|
-
|
|
|
- // 查看执行日志
|
|
|
- if (i % 200 == 0) {
|
|
|
- log.info("line, i=" + i +", " +line);
|
|
|
- }
|
|
|
-
|
|
|
- if (line.contains("done.")) {
|
|
|
- log.info("line: {}", line);
|
|
|
- }
|
|
|
- i++;
|
|
|
- }
|
|
|
- log.info("执行总行数:" +i);
|
|
|
-
|
|
|
- // 结束命令行
|
|
|
- int isCmd = exec.waitFor();
|
|
|
-
|
|
|
- // 关闭流
|
|
|
- br.close();
|
|
|
- errorBuf.close();
|
|
|
-
|
|
|
- return isCmd;
|
|
|
-
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
public static void callLine(String command){
|
|
|
callLine(command, null);
|
|
|
|