Skip to content

Instantly share code, notes, and snippets.

@jeffmaury
Last active August 16, 2016 15:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save jeffmaury/ba61c91fe910220585e9893540ccec7d to your computer and use it in GitHub Desktop.
Save jeffmaury/ba61c91fe910220585e9893540ccec7d to your computer and use it in GitHub Desktop.
package org.jboss.tools.openshift.cdk.server.core.internal.adapter.controllers;
import java.util.*;
import java.io.*;
class StreamGobbler extends Thread
{
InputStream is;
String type;
StreamGobbler(InputStream is, String type)
{
this.is = is;
this.type = type;
}
public void run()
{
try
{
InputStreamReader isr = new InputStreamReader(is);
BufferedReader br = new BufferedReader(isr);
String line=null;
while ( (line = br.readLine()) != null)
System.out.println(type + ">" + line);
} catch (IOException ioe)
{
ioe.printStackTrace();
}
}
}
public class VagrantLauncher
{
public static void main(String args[])
{
try
{
String[] cmd = new String[4];
cmd[0] = args[0];
cmd[1] = "up";
cmd[2] = "--no-color";
cmd[3] = "--debug";
Runtime rt = Runtime.getRuntime();
List<String> envp = new ArrayList<>();
for(Map.Entry<String, String> entry : System.getenv().entrySet()) {
envp.add(entry.getKey() + "=" + entry.getValue());
}
System.out.println("Execing " + cmd[0] + " " + cmd[1]
+ " " + cmd[2]);
envp.add("SUB_USERNAME=" + args[2]);
envp.add("SUB_PASSWORD=" + args[3]);
Process proc = rt.exec(cmd, envp.toArray(new String[0]), new File(args[1]));
// any error message?
StreamGobbler errorGobbler = new
StreamGobbler(proc.getErrorStream(), "ERROR");
// any output?
StreamGobbler outputGobbler = new
StreamGobbler(proc.getInputStream(), "OUTPUT");
// kick them off
errorGobbler.start();
outputGobbler.start();
// any error???
int exitVal = proc.waitFor();
System.out.println("waitFor returned:" + exitVal);
outputGobbler.join();
System.out.println("output thread died");
errorGobbler.join();
System.out.println("error thread died");
} catch (Throwable t)
{
t.printStackTrace();
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment