Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package bot_versie_18;
- import java.io.BufferedReader;
- import java.io.IOException;
- import java.io.InputStreamReader;
- public class ShellExecute
- {
- public static String[] exe(String cmd)
- {
- String[] output = new String[11];
- output[0] = "error";
- int aantalLines = 0;
- Runtime run = Runtime.getRuntime();
- Process pr;
- try
- {
- pr = run.exec(cmd);
- pr.waitFor();
- BufferedReader buf = new BufferedReader(new InputStreamReader(pr.getInputStream()));
- String line = "";
- while ((line = buf.readLine()) != null)
- {
- if (aantalLines <= 10)
- {
- output[aantalLines] = line;
- }
- aantalLines++;
- }
- output[10] = "Amount of lines: " + aantalLines;
- } catch (IOException e)
- {
- // TODO Auto-generated catch block
- e.printStackTrace();
- } catch (InterruptedException e)
- {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
- return output;
- }
- public static String oneLine(String cmd)
- {
- Runtime run = Runtime.getRuntime();
- Process pr;
- try
- {
- pr = run.exec(cmd);
- pr.waitFor();
- BufferedReader buf = new BufferedReader(new InputStreamReader(pr.getInputStream()));
- String line = "";
- while ((line = buf.readLine()) != null)
- {
- return line;
- }
- } catch (IOException e)
- {
- // TODO Auto-generated catch block
- e.printStackTrace();
- } catch (InterruptedException e)
- {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
- return null;
- }
- }
Add Comment
Please, Sign In to add comment