Advertisement
Guest User

Untitled

a guest
Aug 16th, 2016
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.39 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[4];
  38. cmd[0] = args[0];
  39. cmd[1] = "up";
  40. cmd[2] = "--no-color";
  41. cmd[3] = "--debug";
  42. Runtime rt = Runtime.getRuntime();
  43. List<String> envp = new ArrayList<>();
  44. for(Map.Entry<String, String> entry : System.getenv().entrySet()) {
  45. envp.add(entry.getKey() + "=" + entry.getValue());
  46. }
  47. System.out.println("Execing " + cmd[0] + " " + cmd[1]
  48. + " " + cmd[2]);
  49. envp.add("SUB_USERNAME=" + args[2]);
  50. envp.add("SUB_PASSWORD=" + args[3]);
  51. Process proc = rt.exec(cmd, envp.toArray(new String[0]), new File(args[1]));
  52. // any error message?
  53. StreamGobbler errorGobbler = new
  54. StreamGobbler(proc.getErrorStream(), "ERROR");
  55.  
  56. // any output?
  57. StreamGobbler outputGobbler = new
  58. StreamGobbler(proc.getInputStream(), "OUTPUT");
  59.  
  60. // kick them off
  61. errorGobbler.start();
  62. outputGobbler.start();
  63.  
  64. // any error???
  65. int exitVal = proc.waitFor();
  66. System.out.println("waitFor returned:" + exitVal);
  67. outputGobbler.join();
  68. System.out.println("output thread died");
  69. errorGobbler.join();
  70. System.out.println("error thread died");
  71. } catch (Throwable t)
  72. {
  73. t.printStackTrace();
  74. }
  75. }
  76. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement