Created
February 17, 2019 11:51
-
-
Save trongvu/b1b36305dd3a6faae5eac51bc4b94145 to your computer and use it in GitHub Desktop.
Runtime.exec
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 void onCLick(View view) { | |
String cmd = "monkey -p com.google.android.calculator --throttle 200 -v 10000"; | |
try { | |
final Process p = Runtime.getRuntime().exec(cmd); | |
new Thread(() -> { | |
try { | |
InputStreamReader isr = new InputStreamReader (p.getInputStream()); | |
BufferedReader br = new BufferedReader(isr); | |
while (true) { | |
String s = br.readLine (); | |
if (s == null) break; | |
System.out.println (s); | |
} | |
p.getInputStream().close (); | |
} catch (Exception ex) { | |
System.out.println ("Problem reading stream getInputStream: " + ex); | |
ex.printStackTrace (); | |
} | |
}).run(); | |
new Thread(() -> { | |
try { | |
InputStreamReader isr = new InputStreamReader (p.getErrorStream()); | |
BufferedReader br = new BufferedReader(isr); | |
while (true) { | |
String s = br.readLine (); | |
if (s == null) break; | |
System.out.println (s); | |
} | |
p.getInputStream().close (); | |
} catch (Exception ex) { | |
System.out.println ("Problem reading stream getErrorStream: " + ex); | |
ex.printStackTrace (); | |
} | |
}).run(); | |
p.waitFor(); | |
} catch (IOException e) { | |
e.printStackTrace(); | |
} catch (InterruptedException e) { | |
e.printStackTrace(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment