Mattie

Untitled

Feb 10th, 2011
104
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.48 KB | None | 0 0
  1. package bot_versie_18;
  2.  
  3. import java.io.BufferedReader;
  4. import java.io.IOException;
  5. import java.io.InputStreamReader;
  6.  
  7. public class ShellExecute
  8. {
  9.  
  10.     public static String[] exe(String cmd)
  11.     {
  12.         String[] output = new String[11];
  13.         output[0] = "error";
  14.         int aantalLines = 0;
  15.         Runtime run = Runtime.getRuntime();
  16.         Process pr;
  17.         try
  18.         {
  19.             pr = run.exec(cmd);
  20.             pr.waitFor();
  21.             BufferedReader buf = new BufferedReader(new InputStreamReader(pr.getInputStream()));
  22.             String line = "";
  23.             while ((line = buf.readLine()) != null)
  24.             {
  25.                 if (aantalLines <= 10)
  26.                 {
  27.                     output[aantalLines] = line;
  28.                 }
  29.  
  30.                 aantalLines++;
  31.             }
  32.             output[10] = "Amount of lines: " + aantalLines;
  33.  
  34.         } catch (IOException e)
  35.         {
  36.             // TODO Auto-generated catch block
  37.             e.printStackTrace();
  38.         } catch (InterruptedException e)
  39.         {
  40.             // TODO Auto-generated catch block
  41.             e.printStackTrace();
  42.         }
  43.  
  44.         return output;
  45.     }
  46.  
  47.     public static String oneLine(String cmd)
  48.     {
  49.  
  50.         Runtime run = Runtime.getRuntime();
  51.         Process pr;
  52.         try
  53.         {
  54.             pr = run.exec(cmd);
  55.             pr.waitFor();
  56.             BufferedReader buf = new BufferedReader(new InputStreamReader(pr.getInputStream()));
  57.             String line = "";
  58.             while ((line = buf.readLine()) != null)
  59.             {
  60.                 return line;
  61.             }
  62.  
  63.         } catch (IOException e)
  64.         {
  65.             // TODO Auto-generated catch block
  66.             e.printStackTrace();
  67.         } catch (InterruptedException e)
  68.         {
  69.             // TODO Auto-generated catch block
  70.             e.printStackTrace();
  71.         }
  72.  
  73.         return null;
  74.     }
  75. }
Add Comment
Please, Sign In to add comment