package cd.casic.server;

import org.junit.jupiter.api.Test;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.ActiveProfiles;

import java.io.BufferedReader;
import java.io.File;
import java.io.IOException;
import java.io.InputStreamReader;
@SpringBootTest(classes = {OpsServerApplication.class})
@ActiveProfiles("local")
public class ClocTest {
    public void fileExit(){
        File file = new File("/ops-pro/ops-server/src/test/resources/java.zip");
    }

    @Test
    public void test01() throws IOException, InterruptedException {
        // 构建命令
        ProcessBuilder pb = new ProcessBuilder("D:/cloc/cloc.exe", "/ops-pro/ops-server/src/test/resources/java.zip", "--json");
        pb.redirectErrorStream(true); // 合并标准输出和错误输出

        // 启动进程
        Process process = pb.start();
        StringBuilder stringBuilder = new StringBuilder();


        // 读取输出
        try (BufferedReader reader = new BufferedReader(new InputStreamReader(process.getInputStream()))) {
            String line;
            while ((line = reader.readLine()) != null) {
                stringBuilder.append(line);
            }
        }
        System.out.println(stringBuilder.toString());
        // 等待进程结束并获取返回值
        int exitCode = process.waitFor();
        System.out.println("命令执行结束，返回值：" + exitCode);
    }
}
