diff options
author | Ahmet Kerim Senol <akerim@google.com> | 2022-08-16 10:52:02 +0000 |
---|---|---|
committer | Ahmet Kerim Senol <akerim@google.com> | 2022-08-16 16:46:49 +0000 |
commit | 7ba22a470c8090c820f43bf7f372d7518b785fbd (patch) | |
tree | b5d3b3f2b834907fa26d9cd7715a62499ac125ff | |
parent | 30ea6a2f84072839b8df14f54405d73c313c391a (diff) | |
download | base-7ba22a470c8090c820f43bf7f372d7518b785fbd.tar.gz |
Allow emulator process to stream the logs while it's running for easier debugging.
Bug: 240533883
Test: Test changes
Change-Id: I172d739311499d971eea63d9c6a4184fb44b3183
-rw-r--r-- | bazel/avd/src/com/android/tools/bazel/avd/Emulator.java | 23 |
1 files changed, 7 insertions, 16 deletions
diff --git a/bazel/avd/src/com/android/tools/bazel/avd/Emulator.java b/bazel/avd/src/com/android/tools/bazel/avd/Emulator.java index 5817b25b99..fd133787d9 100644 --- a/bazel/avd/src/com/android/tools/bazel/avd/Emulator.java +++ b/bazel/avd/src/com/android/tools/bazel/avd/Emulator.java @@ -16,8 +16,6 @@ package com.android.tools.bazel.avd; -import java.io.BufferedReader; -import java.io.InputStreamReader; import org.junit.rules.ExternalResource; /** JUnit rule that calls the executable generated by the avd rule to start and stop an emulator. */ @@ -40,7 +38,7 @@ public final class Emulator extends ExternalResource { @Override public void before() throws Throwable { System.out.println("Starting emulator"); - System.out.println(exec(devicePath + " " + port)); + exec(devicePath, port); System.out.println("Emulator started"); } @@ -48,25 +46,18 @@ public final class Emulator extends ExternalResource { public void after() { try { System.out.println("Killing emulator"); - System.out.println(exec(devicePath + " kill " + port)); + exec(devicePath, "kill", port); System.out.println("Emulator killed"); } catch (Exception ex) { ex.printStackTrace(); } } - private static String exec(String cmd) throws Exception { - Runtime r = Runtime.getRuntime(); - Process p = r.exec(cmd); - p.waitFor(); - String res = ""; - try (BufferedReader b = new BufferedReader(new InputStreamReader(p.getInputStream()))) { - String l = ""; - while ((l = b.readLine()) != null) { - res += l + "\n"; - } - } + private static void exec(String... cmd) throws Exception { + int exitCode = new ProcessBuilder().command(cmd).inheritIO().start().waitFor(); - return res; + if (exitCode != 0) { + throw new Exception(String.format("Emulator script exited with code: %d", exitCode)); + } } } |