Created
July 11, 2014 10:29
-
-
Save bogdan-nourescu/e606a1f723c6ae5a73fc to your computer and use it in GitHub Desktop.
This file contains 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
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