Skip to content

Instantly share code, notes, and snippets.

@bogdan-nourescu
Created July 11, 2014 10:29
Show Gist options
  • Save bogdan-nourescu/e606a1f723c6ae5a73fc to your computer and use it in GitHub Desktop.
Save bogdan-nourescu/e606a1f723c6ae5a73fc to your computer and use it in GitHub Desktop.
public static String exec(String command) {
try {
Process p1 = Runtime.getRuntime().exec(command);
p1.waitFor();
BufferedReader reader =
new BufferedReader(new InputStreamReader(p1.getInputStream()));
StringBuilder sb = new StringBuilder();
StringBuilder sb2 = new StringBuilder();
String line;
while ((line = reader.readLine()) != null) {
sb.append(line).append("\n");
}
reader = new BufferedReader(new InputStreamReader(p1.getErrorStream()));
while ((line = reader.readLine()) != null) {
sb2.append(line).append("\n");
}
return sb.toString() + sb2.toString();
} catch (IOException | InterruptedException e) {
Log.w(e);
return e.getMessage();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment