Advertisement
Guest User

Untitled

a guest
Jun 15th, 2016
95
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.36 KB | None | 0 0
  1. package org.jboss.tools.openshift.cdk.server.core.internal.adapter.controllers;
  2.  
  3. import java.util.*;
  4. import java.io.*;
  5. class StreamGobbler extends Thread
  6. {
  7. InputStream is;
  8. String type;
  9.  
  10. StreamGobbler(InputStream is, String type)
  11. {
  12. this.is = is;
  13. this.type = type;
  14. }
  15.  
  16. public void run()
  17. {
  18. try
  19. {
  20. InputStreamReader isr = new InputStreamReader(is);
  21. BufferedReader br = new BufferedReader(isr);
  22. String line=null;
  23. while ( (line = br.readLine()) != null)
  24. System.out.println(type + ">" + line);
  25. } catch (IOException ioe)
  26. {
  27. ioe.printStackTrace();
  28. }
  29. }
  30. }
  31. public class VagrantLauncher
  32. {
  33. public static void main(String args[])
  34. {
  35. try
  36. {
  37. String[] cmd = new String[3];
  38. cmd[0] = args[0];
  39. cmd[1] = "up";
  40. cmd[2] = "--no-color";
  41. Runtime rt = Runtime.getRuntime();
  42. List<String> envp = new ArrayList<>();
  43. for(Map.Entry<String, String> entry : System.getenv().entrySet()) {
  44. envp.add(entry.getKey() + "=" + entry.getValue());
  45. }
  46. System.out.println("Execing " + cmd[0] + " " + cmd[1]
  47. + " " + cmd[2]);
  48. envp.add("SUB_USERNAME=" + args[2]);
  49. envp.add("SUB_PASSWORD=" + args[3]);
  50. Process proc = rt.exec(cmd, envp.toArray(new String[0]), new File(args[1]));
  51. // any error message?
  52. StreamGobbler errorGobbler = new
  53. StreamGobbler(proc.getErrorStream(), "ERROR");
  54.  
  55. // any output?
  56. StreamGobbler outputGobbler = new
  57. StreamGobbler(proc.getInputStream(), "OUTPUT");
  58.  
  59. // kick them off
  60. errorGobbler.start();
  61. outputGobbler.start();
  62.  
  63. // any error???
  64. int exitVal = proc.waitFor();
  65. System.out.println("waitFor returned:" + exitVal);
  66. outputGobbler.join();
  67. System.out.println("output thread died");
  68. errorGobbler.join();
  69. System.out.println("error thread died");
  70. } catch (Throwable t)
  71. {
  72. t.printStackTrace();
  73. }
  74. }
  75. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement