import java.io.*;
import java.util.*;

public class phptest {
   public static void main(String args[]) 
   throws Throwable {
        String env[]=
        {
"C:\\PHP4.2.2\\php.exe", 
"cgi-bin\\hello.php",
"ALLUSERSPROFILE=C:\\Documents and Settings\\All Users",
"ANT_HOME=C:\\Ant\\",
"CLASSPATH=.\\",
"CommonProgramFiles=C:\\Program Files\\Common Files",
"COMPUTERNAME=MATTS",
"ComSpec=C:\\WINNT\\system32\\cmd.exe",
"CONTENT_LENGTH=0",
"GATEWAY_INTERFACE=CGI/1.1",
"HTTPS=off",
"HTTP_ACCEPT=*/*",
"HTTP_ACCEPT_LANGUAGE=en-us",
"HTTP_CONNECTION=Keep-Alive",
"HTTP_HOST=127.0.0.1",
"HTTP_USER_AGENT=Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.0; .NET CLR 1.0.3705)",
"HTTP_ACCEPT_ENCODING=gzip, deflate",
"QUERY_STRING=name=Matthew+W.+Coan",
"INSTANCE_ID=1",
"JAVA_HOME=C:\\jdk1.3.1_01\\",
"LOCAL_ADDR=127.0.0.1",
"NUMBER_OF_PROCESSORS=1",
"Os2LibPath=C:\\WINNT\\system32\\os2\\dll;",
"OS=Windows_NT",
"Path=C:\\JavaCC2.1\\bin;C:\\Ant\\bin;C:\\jdk1.3.1_01\\bin;C:\\WINNT\\system32;C:\\WINNT;C:\\WINNT\\System32\\Wbem;C:\\Program Files\\Symantec\\pcAnywhere\\;C:\\Program Files\\Common Files\\Adaptec Shared\\System;C:\\MSSQL7\\BINN",
"PATHEXT=.COM;.EXE;.BAT;.CMD;.VBS;.VBE;.JS;.JSE;.WSF;.WSH",
"PATH_TRANSLATED=C:\\Development\\httpd\\cgi-bin",
"PROCESSOR_ARCHITECTURE=x86",
"PROCESSOR_IDENTIFIER=x86 Family 6 Model 8 Stepping 3, GenuineIntel",
"PROCESSOR_LEVEL=6",
"PROCESSOR_REVISION=0803",
"ProgramFiles=C:\\Program Files",
"REMOTE_ADDR=127.0.0.1",
"REMOTE_HOST=127.0.0.1",
"REQUEST_METHOD=GET",
"SCRIPT_NAME=/cgi-bin/hello.php",
"SERVER_NAME=127.0.0.1",
"SERVER_PORT=80",
"SERVER_PORT_SECURE=0",
"SERVER_PROTOCOL=HTTP/1.1",
"SERVER_SOFTWARE=Microsoft-IIS/5.0",
"SystemDrive=C:",
"SystemRoot=C:\\WINNT",
"TEMP=C:\\WINNT\\TEMP",
"TMP=C:\\WINNT\\TEMP",
"USERPROFILE=C:\\Documents and Settings\\Administrator",
"windir=C:\\WINNT"
        };
        Process p = Runtime.getRuntime().exec(/*
            new String[] {
            "C:\\PHP4.2.2\\php.exe", 
            "cgi-bin\\hello.php"},*/
                    env);
        try
        {
            // read any headers off the top of our input stream
            BufferedReader br = new BufferedReader(new InputStreamReader(p.getInputStream()));
            String line;
            LinkedList list = new LinkedList();
            while((line = br.readLine()) != null) {
System.out.println("HEADER("+line+")");
               if(line.compareTo("") == 0)
                  break;
               list.add(line);
            }

            PrintWriter out = new PrintWriter(new OutputStreamWriter(System.out));
            char buf[] = new char[7*1024];
            int n;
System.out.println("WRITE CONTENT NEXT!");
            while((n = br.read(buf)) > -1) {
//System.out.print(new String(buf,0,n));
               out.write(buf, 0, n);
               out.flush();
            }
            br.close();
System.out.println("DONE!");
        }
        catch (IOException e)
        {
            p.destroy();
        }
   }
}