Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 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[3];
- 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);
- System.exit(exitVal);
- // outputGobbler.join();
- // System.out.println("output thread died");
- // errorGobbler.join();
- // System.out.println("error thread died");
- } catch (Throwable t)
- {
- t.printStackTrace();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement