Advertisement
Guest User

Untitled

a guest
Apr 8th, 2015
342
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.79 KB | None | 0 0
  1. public static String runExternalCommand(String cmd) {
  2.         String output = "";
  3.         String errMsg = "";
  4.  
  5.         try {
  6.             Process command = Runtime.getRuntime().exec(cmd);
  7.  
  8.             BufferedReader in = new BufferedReader(new InputStreamReader(
  9.                     command.getInputStream()));
  10.             String line = "";
  11.             while ((line = in.readLine()) != null) {
  12.                 output += line + "\n";
  13.             }
  14.             in.close();
  15.  
  16.             BufferedReader br = new BufferedReader(new InputStreamReader(
  17.                     command.getErrorStream()));
  18.  
  19.             while ((line = br.readLine()) != null) {
  20.  
  21.                 errMsg += line + "\n";
  22.  
  23.             }
  24.             br.close();
  25.  
  26.         } catch (Exception e) {
  27.             Log.v("AppImp",
  28.                     "Exception when trying to execute external command "
  29.                             + e.getMessage());
  30.         }
  31.         Log.v("AppImp", output);
  32.         Log.v("AppImp", errMsg);
  33.         return output;
  34.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement