package org.flatland.drip;
import java.lang.reflect.Method;
import java.io.*;
import java.util.Scanner;
import java.util.LinkedList;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class Main {
  static private Scanner s;

  public static void main(String[] args) throws Exception {
    String class_name = args[0];
    String fifo_dir   = args[1];

    reopenStreams(fifo_dir);
    Method main = mainMethod(class_name);

    Method init       = mainMethod(System.getenv("DRIP_INIT_CLASS"));
    String init_args  = System.getenv("DRIP_INIT");
    if (init_args != null) mainInvoke(init == null ? main : init, init_args);

    String main_args    = readline();
    String runtime_args = readline();
    setProperties(runtime_args);

    mainInvoke(main, main_args);
    System.exit(0);
  }

  private static Method mainMethod(String class_name)
    throws ClassNotFoundException, NoSuchMethodException {
    if (class_name != null) {
      return Class.forName(class_name).getMethod("main", String[].class);
    } else {
      return null;
    }
  }

  private static void mainInvoke(Method main, String main_args) throws Exception {
    Scanner s = new Scanner(main_args);
    s.useDelimiter("\t");
    LinkedList<String> args = new LinkedList<String>();
    while (s.hasNext()) {
      args.add(s.next());
    }
    main.invoke(null, (Object)args.toArray(new String[0]));
  }

  private static void setProperties(String runtime_args) {
    Matcher m = Pattern.compile("-D([^=]+)=([^\\t]+)").matcher(runtime_args);

    while (m.find()) {
      System.setProperty(m.group(1), m.group(2));
    }
  }

  private static void reopenStreams(String fifo_dir) throws FileNotFoundException, IOException {
    System.in.close();
    System.out.close();
    System.err.close();
    System.setIn(new BufferedInputStream(new DelayedFileInputStream(fifo_dir + "/in")));
    System.setOut(new PrintStream(new DelayedFileOutputStream(fifo_dir + "/out")));
    System.setErr(new PrintStream(new DelayedFileOutputStream(fifo_dir + "/err")));
    s = new Scanner(System.in);
  }

  public static String readline() throws IOException {
    if (s.hasNextLine()) {
      return s.nextLine();
    } else {
      return "";
    }
  }
}

@@ -69,12 +69,66 @@
 ava.
-io.*
+lang.reflect.Field;%0Aimport java.io.*;%0Aimport java.util.Map
 ;%0Aim
@@ -1664,32 +1664,548 @@
 2));%0A    %7D%0A  %7D%0A%0A
+  private static void setEnv(Map%3CString, String%3E newEnv) throws NoSuchFieldException, IllegalAccessException %7B%0A    Map%3CString, String%3E env = System.getenv();%0A    Class%3C?%3E classToHack = env.getClass();%0A    if (!(classToHack.getName().equals(%22java.util.Collections$UnmodifiableMap%22))) %7B%0A      throw new RuntimeException(%22Don't know how to hack %22 + classToHack);%0A    %7D%0A%0A    Field field = classToHack.getDeclaredField(%22m%22);%0A    field.setAccessible(true);%0A    field.set(env, newEnv);%0A    field.setAccessible(false);%0A  %7D%0A%0A
   private static

Add hacky setEnv.