thufir

Untitled

Sep 5th, 2013
62
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.86 KB | None | 0 0
  1. package exec;
  2.  
  3. import java.io.BufferedReader;
  4. import java.io.IOException;
  5. import java.io.InputStream;
  6. import java.io.InputStreamReader;
  7. import java.io.OutputStream;
  8. import java.io.UnsupportedEncodingException;
  9.  
  10. class Ideone {
  11.  
  12.     public static void main(String[] args) throws IOException {
  13.         new Ideone().start();
  14.     }
  15.  
  16.     public void start() throws IOException {
  17.         String[] s = new String[3];
  18.         s[0] = "telnet";
  19.         s[1] = "rainmaker.wunderground.com";
  20.         s[2] = "3000";
  21.         s[3] = "|";
  22.         s[4] = "tee";
  23.         s[5] = "out.log";
  24.         Process process = Runtime.getRuntime().exec(s);
  25.         OutputStream stdin = process.getOutputStream();
  26.         InputStream stderr = process.getErrorStream();
  27.         InputStream stdout = process.getInputStream();
  28.         read();
  29.         write(stdout);
  30.     }
  31.  
  32.     private void parseLog() {
  33.         //read the log file, automate responses
  34.     }
  35.  
  36.     private void write(InputStream stdin) throws UnsupportedEncodingException, IOException {
  37.         BufferedReader reader = new BufferedReader(new InputStreamReader(stdin, "UTF-8"));
  38.         String line;
  39.         while ((line = reader.readLine()) != null) {
  40.             System.out.println(line);
  41.         }
  42.  
  43.     }
  44.  
  45.     private void read() {
  46.  
  47.         Thread read = new Thread() {
  48.  
  49.             String command = null;
  50.  
  51.             @Override
  52.             public void run() {
  53.                 BufferedReader bufferedInput = new BufferedReader(new InputStreamReader(System.in));
  54.                 do {
  55.                     try {
  56.                         command = bufferedInput.readLine();
  57.                     } catch (IOException ex) {
  58.                         System.out.println(ex);
  59.                     } finally {
  60.                     }
  61.                 } while (true);
  62.             }
  63.         };
  64.         read.start();
  65.     }
  66. }
Advertisement
Add Comment
Please, Sign In to add comment