package com.peony.common.util;

import java.io.BufferedInputStream;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.List;

/**
* @projectName: server
* @package: com.peony.common.util
* @className: ShellUtils
* @author: zy
* @description:
* @date: 2022-06-29 16:32
*/
public class ShellUtils {
/**
* 脚本路径或者命令
* @param pathOrCommand
* @return
*/
public static List<String> exceShell(String pathOrCommand){
ArrayList<String> list = new ArrayList<>();
try{
Process exec = Runtime.getRuntime().exec(pathOrCommand);
int i = exec.waitFor();
if(0!=i){
list.add("执行错误,error code :"+i);
}
BufferedInputStream inputStream = new BufferedInputStream(exec.getInputStream());
BufferedReader reader = new BufferedReader(new InputStreamReader(inputStream));
String li=null;
while ((li=reader.readLine())!=null){
list.add(li);
}
}catch (Exception e){
e.printStackTrace();
}

return list;
}

}