Created
January 11, 2021 03:59
-
-
Save Malinskiy/85c89097f13251bfc61527de181f1112 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private static String readLogcat(long startTimeMs) { | |
try { | |
... | |
// Start the process | |
final Process process = new ProcessBuilder() | |
.command("logcat", "-d", "-v threadtime,uid", "-T", timestamp) | |
.start(); | |
// Nothing to write. Don't let the command accidentally block. | |
process.getOutputStream().close(); | |
// Read the output | |
final StringBuilder str = new StringBuilder(); | |
final InputStreamReader reader = new InputStreamReader(process.getInputStream()); | |
char[] buffer = new char[4096]; | |
int amt; | |
while ((amt = reader.read(buffer, 0, buffer.length)) >= 0) { | |
if (amt > 0) { | |
str.append(buffer, 0, amt); | |
} | |
} | |
try { | |
process.waitFor(); | |
} catch (InterruptedException ex) { | |
// We already have the text, drop the exception. | |
} | |
return str.toString(); | |
} catch (IOException ex) { | |
return "Error reading logcat command:\n" + ex.toString(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment