Advertisement
petesh

This is the current model (for safety of stdout and stderr)

Sep 15th, 2015
103
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.17 KB | None | 0 0
  1.  
  2. import java.io.*;
  3.  
  4. class gobbler extends Thread {
  5.     InputStream is;
  6.     StringBuilder output;
  7.  
  8.     public gobbler(InputStream is) {
  9.         this.is = is;
  10.         output = new StringBuilder();
  11.     }
  12.  
  13.     public String getOutput() {
  14.         return output.toString();
  15.     }
  16.  
  17.     public void run() {
  18.         try {
  19.             String line;
  20.             BufferedReader br = new BufferedReader(new InputStreamReader(is));
  21.             while ((line = br.readLine()) != null) {
  22.                 output.append(line);
  23.                 output.append("\n");
  24.             }
  25.         } catch (IOException ioe) {
  26.             ioe.printStackTrace();
  27.         }
  28.     }
  29. };
  30.  
  31. public class props {
  32.     public static void main(String[] args) throws Exception {
  33.         Process process = Runtime.getRuntime().exec("openssl s_client -no_ign_eof -connect google.com:443 -cipher RC4-SHA");
  34.         gobbler stdout = new gobbler(process.getInputStream());
  35.         gobbler stderr = new gobbler(process.getErrorStream());
  36.  
  37.         stdout.start();
  38.         stderr.start();
  39.  
  40.         process.getOutputStream().close();
  41.  
  42.         System.out.println("Waiting for process to terminate ...");
  43.         process.waitFor();
  44.         System.out.print(stdout.getOutput());
  45.         System.out.print(stderr.getOutput());
  46.         System.out.println("Exiting ...");
  47.     }
  48. };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement