Advertisement
Guest User

Untitled

a guest
Apr 25th, 2015
239
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.57 KB | None | 0 0
  1. public static String command(String cmd) throws Exception {
  2.  
  3.     String out = "";
  4.     Runtime runtime = Runtime.getRuntime();
  5.     process proc = runtime.exec(cmd);
  6.  
  7.     proc.waitFor();
  8.        
  9.    
  10.  
  11.     InputStream is = proc.getInputStream();
  12.     InputStreamReader isr = new InputStreamReader(is);
  13.     BufferedReader br = new BufferedReader(isr);
  14.  
  15.     String line;
  16.     while ((line = br.readLine()) != null) {
  17.         System.out.println(line);
  18.         if (!out.equals(""))
  19.             out += '\n';
  20.  
  21.         System.out.println(line);
  22.  
  23.         out += line;
  24.     }
  25.     if(proc.exitValue() == 1)
  26.         throw exErrorOne;
  27.        
  28.        
  29.  
  30.     return out;
  31. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement