Untitled
unknown
plain_text
a month ago
2.3 kB
1
Indexable
Never
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; public class RunCtsTest { public static void main(String[] args) { try { // Mở một terminal và chạy lệnh ./cts-tradefed ProcessBuilder builder = new ProcessBuilder("/bin/bash", "-c", "./cts-tradefed"); Process terminalProcess = builder.start(); // Đọc đầu ra từ terminal BufferedReader reader = new BufferedReader(new InputStreamReader(terminalProcess.getInputStream())); String line; while ((line = reader.readLine()) != null) { System.out.println(line); // Nếu tìm thấy "PASS", chạy lệnh kill if (line.contains("PASS")) { Process killProcess = new ProcessBuilder("/bin/bash", "-c", "kill <PID>").start(); // Thay <PID> bằng Process ID của terminal killProcess.waitFor(); break; } // Nếu tìm thấy "All done", sao chép file test_result.xml if (line.contains("All done")) { Process copyProcess = new ProcessBuilder("/bin/bash", "-c", "cp /home/ga/cts/tools/123/test_result.xml /home/ga/cts/tools/234/").start(); copyProcess.waitFor(); } } // Chạy lệnh run retry -r 2 Process retryProcess = new ProcessBuilder("/bin/bash", "-c", "./cts-tradefed run retry -r 2").start(); // Đọc đầu ra từ terminal retry BufferedReader retryReader = new BufferedReader(new InputStreamReader(retryProcess.getInputStream())); while ((line = retryReader.readLine()) != null) { System.out.println(line); // Nếu tìm thấy "PASS", chạy lệnh kill if (line.contains("PASS")) { Process killProcess = new ProcessBuilder("/bin/bash", "-c", "kill <PID>").start(); // Thay <PID> bằng Process ID của terminal retry killProcess.waitFor(); break; } } } catch (IOException | InterruptedException e) { e.printStackTrace(); } } }