package net.northking.cctp.upperComputer.utils;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.io.IOException;
import java.util.List;
import java.util.stream.Collectors;

public class ProcessCmdUtils {

    private static final Logger logger = LoggerFactory.getLogger(ProcessCmdUtils.class);

    public static Process execCmd(List<String> commands){
        ProcessBuilder processBuilder = new ProcessBuilder(commands);
        processBuilder.redirectErrorStream(true);
        Process start = null;
        try {
            logger.info("开始执行cmd命令：{}",commands.stream().collect(Collectors.joining(" ")));
            start = processBuilder.start();
        } catch (IOException e) {
            logger.error("命令：{}",commands);
            logger.error("执行命令失败",e);

        }
        return start;
    }
}
