Index: main/trunk/greenstone2/runtime-src/src/recpt/os_process.cpp
===================================================================
--- main/trunk/greenstone2/runtime-src/src/recpt/os_process.cpp	(revision 22174)
+++ main/trunk/greenstone2/runtime-src/src/recpt/os_process.cpp	(revision 22177)
@@ -26,6 +26,4 @@
 #include "os_process.h"
 
-osprocess::osprocess(char* cmd)
-{}
 osprocess::osprocess(char* cmdline, OSProcessPipeMode mode)
   : mode_(mode)
@@ -36,32 +34,78 @@
 }
   
-/*
-bool osprocess::eop()
+bool osprocess::close()
 {
+  // close any file handles that are still open
+
+  bool write_close_rv = close_write_pipe(withoutWarning);
+  bool read_close_rv = close_read_pipe(withoutWarning);
+
+  return (write_close_rv && read_close_rv);
 }
 
-bool osprocess::eop(OSProcessPipeMode)
+
+
+
+#if 1
+
+#include "os_process_windows.h"
+#include "os_process_unix.h"
+#include <iostream>
+using namespace std;
+
+void test_uni_write_pipe()
 {
+#ifdef __WIN32__
+  char* prog_name = "c:\\Windows\\system32\\java.exe";
+  char* cmd_line = "java";
+  
+  //char* input_line = "echo hi there\n";
+  //char* prog_name  = "c:\\cygwin\\bin\\cat.exe";
+  //char* cmd_line   = "cat";
+#else
+  char* cmd_line = "/usr/bin/java";
+  //char* cmd_line = "java";
+#endif
+
+#ifdef __WIN32__
+  osprocesswindows* process = new osprocesswindows(cmd_line,uniRead);
+#else
+  osprocessunix* process = new osprocessunix(cmd_line,uniRead);
+#endif
+  
+  const int BufferSize = 1024;
+  char buffer[BufferSize];
+
+  int bytes_read = 0;
+  do {
+    bytes_read = process->read(buffer,BufferSize);
+    if (bytes_read>0) {
+      fwrite(buffer,1,bytes_read,stdout);
+    }
+  } while (bytes_read==BufferSize);
+
+
+  delete process;
+
 }
-*/
 
-int osprocess::read(char* buffer, const int buffer_len)
+int main()
 {
+  printf("Content-type: text/html\n\n");
+  
+  printf( "<html>\n");
+  printf( "  <head>\n");
+  printf( "    <title>Testing</title>\n");
+  printf( "  </head>\n");
+  printf( "  <body>\n");
+
+  test_uni_write_pipe();
+
+  printf( "  </body>\n");
+  printf( "</html>\n");
+  
   return 0;
 }
 
-int osprocess::write(char* buffer, const int buffer_len)
-{
-  return 0;
-}
-  
-bool osprocess::close() 
-{
-  return true;
-}
+#endif
 
-bool osprocess::close(OSProcessPipeMode mode)
-{
-  return true;
-}
-
Index: main/trunk/greenstone2/runtime-src/src/recpt/os_process.h
===================================================================
--- main/trunk/greenstone2/runtime-src/src/recpt/os_process.h	(revision 22174)
+++ main/trunk/greenstone2/runtime-src/src/recpt/os_process.h	(revision 22177)
@@ -33,7 +33,8 @@
 #define OS_PROCESS_H
 
- #include <stdlib.h>
+#include <stdlib.h>
 
-enum OSProcessPipeMode { uniRead=0, uniWrite=1, biReadWrite=2, noPipe=3 };
+enum OSProcessPipeMode   { uniRead=0, uniWrite=1, biReadWrite=2 };
+enum OSProcessWarnStatus { withoutWarning, withWarning };
 
 class osprocess 
@@ -41,23 +42,23 @@
   
  public:
-  osprocess(char* cmdline);
   osprocess(char* cmdline, OSProcessPipeMode mode);
   virtual ~osprocess();
   
-  /*
-  virtual bool eop();                  // end of pipe
-  virtual bool eop(OSProcessPipeMode); // end of pipe, for designated pipe
+  /* one day might want these
+  virtual bool end_of_pipe();  
+  virtual bool end_of_read_pipe(); 
+  virtual bool end_of_write_pipe();
   */
 
-  virtual int write(char* buffer, const int buffer_len);
-  virtual int read(char* buffer, const int buffer_len);
+  virtual int write(char* buffer, const int buffer_len)=0;
+  virtual int read(char* buffer, const int buffer_len)=0;
   
+  virtual bool close_write_pipe(OSProcessWarnStatus warn_status=withWarning)=0;
+  virtual bool close_read_pipe(OSProcessWarnStatus warn_status=withWarning)=0;
   virtual bool close();
-  virtual bool close(OSProcessPipeMode mode);
+
   
  protected:
   OSProcessPipeMode mode_;
-  bool read_pipe_open_;
-  bool write_pipe_open_;
 
 };
Index: main/trunk/greenstone2/runtime-src/src/recpt/os_process_unix.cpp
===================================================================
--- main/trunk/greenstone2/runtime-src/src/recpt/os_process_unix.cpp	(revision 22174)
+++ main/trunk/greenstone2/runtime-src/src/recpt/os_process_unix.cpp	(revision 22177)
@@ -41,15 +41,4 @@
 #include "os_process_unix.h"
 
-#define READ_PIPE_INDEX 0
-#define WRITE_PIPE_INDEX 1
-
-#define FD_STDIN 0
-#define FD_STDOUT 1
-#define FD_STDERR 2
-
-osprocessunix::osprocessunix(char* cmdline)
-  : osprocess(cmdline)
-{}
-
 osprocessunix::osprocessunix(char* cmdline, OSProcessPipeMode mode)
   : child_stdout_read_(-1), child_stdin_write_(-1),
@@ -81,16 +70,17 @@
 
   
-  pid_t pid = fork();
-  if (pid < 0) {
+  pid_ = fork();
+  if (pid_ < 0) {
     cerr << "osprocessunix::osprocessunix(): Failed to create child process" << endl; 
     return;
   }
 
-  if (pid == 0) {
+  if (pid_ == 0) {
     // Child process
 
     // Sort out input pipe
     //   child has no buisness accessing write end of input pipe => close
-    ::close(child_stdin_write_);   
+    ::close(child_stdin_write_); 
+    child_stdin_write_=-1;
 
     if ((mode == uniWrite) || (mode == biReadWrite)) {
@@ -99,6 +89,6 @@
     }
     else {
-      // noPipe or (parent is doing) uniRead (which means we're not interested
-      // in the child reading any input from the parent)
+      // Parent is doing uniRead, which means we're not interested
+      // in the child reading any input from the parent
       // => child input remains coming from stdin
       ::close(child_stdin_read);
@@ -108,4 +98,6 @@
     //   child has no buisness accessing read end of output pipe => close
     ::close(child_stdout_read_);
+    child_stdout_read_=-1;
+
     if ((mode == uniRead) || (mode == biReadWrite)) {
       //   wire up child's stdout write so it is send down the pipe to the parent
@@ -113,26 +105,15 @@
     }
     else {
-      // noPipe or (parent is doing) uniWrite (which means we're not interested
-      // in any output produced by the child process)
+      // Parent is doing uniWrite, which means we're not interested
+      // in any output produced by the child process
       // => child output remains going to stdout
       ::close(child_stdout_write);
     }
 
-    /*
-    // execve ...
-    int rv = CreateProcess(NULL,    // no application name
-			   cmdline, 
-			   NULL, 
-			   NULL,    // no process or thread security attribues 
-			   TRUE,    // Inherit handles
-			   0,       // Creation flag
-			   NULL,    // No environment block
-			   ".",     // current working directory
-			   &si, 
-			   &pi_);    // process info filled out as a result
-    if (!rv) {
-      fprintf(stderr,"os_process_windows(): Error creating process");
-    }
-    */
+    
+    // execvp?
+    cerr << "Away to execve: " << cmdline << endl;
+
+    execve(cmdline, NULL, NULL);
 
     
@@ -154,7 +135,9 @@
       case uniRead:
 	::close(child_stdin_write_);
+	child_stdin_write_ = -1;
 	break;
       case uniWrite:
 	::close(child_stdout_read_);
+	child_stdout_read_ = -1;
 	break;
       case biReadWrite:
@@ -162,8 +145,4 @@
 	// the pipes are set up just the way we want them
 	break;
-      case noPipe:
-	::close(child_stdin_write_);
-	::close(child_stdout_read_);
-	break;
     }
   }
@@ -171,13 +150,9 @@
 
 osprocessunix::~osprocessunix()
-{}
-
-/*  
-bool osprocessunix::eop()
-{}
-
-bool osprocessunix::eop(OSProcessPipeMode)
-{}
-*/
+{
+  // close any file handles that are still open
+  close();
+}
+
 
 int osprocessunix::write(char* buffer, const int buffer_len)
@@ -206,13 +181,38 @@
 
   
-bool osprocessunix::close()
-{
-  return true;
-}
-
-bool osprocessunix::close(OSProcessPipeMode mode)
-{
-  return true;
-}
+bool osprocessunix::close_write_pipe(OSProcessWarnStatus warn_status)
+{
+  int write_close_rv = 0;
+
+  if (child_stdin_write_ != -1) {
+    write_close_rv = ::close(child_stdin_write_);
+    child_stdin_write_ = -1;
+  }
+  else if (warn_status = withWarning) {
+    cerr << "osprocessunix::close_write_pipe(): Warning - Tried to close already closed pipe" << endl;
+  }
+
+  return (write_close_rv==0);
+}
+
+
+bool osprocessunix::close_read_pipe(OSProcessWarnStatus warn_status)
+{
+  int read_close_rv = 0;
+
+
+  if (child_stdout_read_ != -1) {
+    read_close_rv = ::close(child_stdout_read_);
+    child_stdout_read_ = -1;
+  }
+  else if (warn_status == withWarning) {
+    cerr << "osprocessunix::close_read_pipe(): Warning - Tried to close already closed pipe" << endl;
+  }
+
+  return (read_close_rv==0);
+}
+
+
+
 
 
Index: main/trunk/greenstone2/runtime-src/src/recpt/os_process_unix.h
===================================================================
--- main/trunk/greenstone2/runtime-src/src/recpt/os_process_unix.h	(revision 22174)
+++ main/trunk/greenstone2/runtime-src/src/recpt/os_process_unix.h	(revision 22177)
@@ -38,20 +38,24 @@
    
  public:
-  osprocessunix(char* cmd);
   osprocessunix(char* cmd, OSProcessPipeMode mode);
   virtual ~osprocessunix();
   
-  /*
-  virtual bool eop();                  // end of pipe
-  virtual bool eop(OSProcessPipeMode); // end of pipe, for designated pipe
-  */
-
   virtual int read(char* buffer, const int buffer_len);
   virtual int write(char* buffer, const int buffer_len);
   
-  virtual bool close();
-  virtual bool close(OSProcessPipeMode mode);
+  virtual bool close_write_pipe(OSProcessWarnStatus warn_status=withWarning);
+  virtual bool close_read_pipe(OSProcessWarnStatus warn_status=withWarning);
 
  protected:
+
+  static const int READ_PIPE_INDEX=0;
+  static const int WRITE_PIPE_INDEX=1;
+
+  static const int FD_STDIN=0;
+  static const int FD_STDOUT=1;
+  static const int FD_STDERR=2;
+
+  pid_t pid_;
+
   int child_stdin_write_;
   int child_stdout_read_;
Index: main/trunk/greenstone2/runtime-src/src/recpt/os_process_windows.cpp
===================================================================
--- main/trunk/greenstone2/runtime-src/src/recpt/os_process_windows.cpp	(revision 22174)
+++ main/trunk/greenstone2/runtime-src/src/recpt/os_process_windows.cpp	(revision 22177)
@@ -130,4 +130,7 @@
 osprocesswindows::~osprocesswindows() 
 {
+  // close any file handles that are still open
+  close();
+
   // Close process and thread handles
   CloseHandle( pi_.hProcess );  
@@ -137,15 +140,4 @@
   pi_.hThread = NULL;
 }
-
-
-/*
-bool osprocesswindows::eop()
-{
-}
-
-bool osprocesswindows::eop(OSProcessPipeMode)
-{
-}
-*/
 
 
@@ -178,73 +170,58 @@
 
 
-bool osprocesswindows::close() {
-  return true;
-}
-
-bool osprocesswindows::close(OSProcessPipeMode mode) 
-{
-  // Close the pipe handle so the child process stops reading. 
-  
-  if (!CloseHandle(child_stdin_write_)) {
-    cerr << "osprocesswindows::close(): Failed to close stdin write handle on pipe to child process" << endl;
-    return false;
-  }
-
-  if (!CloseHandle(child_stdout_read_)) {
-    cerr << "osprocesswindows::close(): Failed to close handle stdout read on pipe to chlild process" << endl;
-    return false;
-  }
-
-
-  return true;
-}
-
-
-
-
-
-//#ifdef TEST_OS_PROCESS_WINDOWS
-#if 0
-
-int main ()
-{
-  char* input_line = NULL;
-  char* prog_name = "c:\\Windows\\system32\\java.exe";
-  char* cmd_line = "java";
-  
-  //char* input_line = "echo hi there\n";
-  //char* prog_name  = "c:\\cygwin\\bin\\cat.exe";
-  //char* cmd_line   = "cat";
-
-  osprocesswindows osprocess(cmd_line,uniRead);
-
-  printf("Content-type: text/html\n\n");
-  
-  printf( "<html>\n");
-  printf( "  <head>\n");
-  printf( "    <title>Testing</title>\n");
-  printf( "  </head>\n");
-  printf( "  <body>\n");
-  
-
-  const int BufferSize = 1024;
-  char buffer[BufferSize];
-
-  int bytes_read = 0;
-  do {
-    bytes_read = osprocess.read(buffer,BufferSize);
-    if (bytes_read>0) {
-      fwrite(buffer,1,bytes_read,stdout);
-    }
-  } while (bytes_read==BufferSize);
-
-
-  printf( "  </body>\n");
-  printf( "</html>\n");
-  
-  return 0;
-}
+
+  
+bool osprocessunix::close_write_pipe(OSProcessWarnStatus warn_status)
+{
+  bool write_close_ok = true;
+
+  if (child_stdout_read_ != NULL) {
+
+    write_close_ok = CloseHandle(child_stdin_write_);
+
+    if (write_close_ok) {
+      child_stdin_write_ = NULL;
+    }
+    else {
+      // not OK
+      cerr << "osprocesswindows::close(): Error - Failed to close stdin write handle on pipe to child process" << endl;
+    }
+  }
+  else if (warning_status == withWarning) {
+    cerr << "osprocesswindows::close_write_pipe(): Warning - Tried to close already closed pipe" << endl;
+  }
+
+  return write_close_ok;
+}
+
+
+bool osprocessunix::close_read_pipe(OSProcessWarnStatus warn_status)
+{
+  bool read_close_ok = true;
+  
+  if (child_stdout_read_ != NULL) {
+    
+    read_close_ok = CloseHandle(child_stdout_read_);
+    
+    if (read_close_ok) {
+      child_stdout_read_ = NULL;
+    }
+    else {
+      cerr << "osprocesswindows::close(): Error - Failed to close handle stdout read on pipe to chlild process" << endl;
+    }
+  }
+  else if (warn_status == withWarning) {
+    cerr << "osprocesswindows::close_read_pipe(): Warning - Tried to close already closed pipe" << endl;
+  }
+  
+  return read_close_ok;
+}
+
+
+
+
+
+
+
 
 #endif
-
-#endif
Index: main/trunk/greenstone2/runtime-src/src/recpt/os_process_windows.h
===================================================================
--- main/trunk/greenstone2/runtime-src/src/recpt/os_process_windows.h	(revision 22174)
+++ main/trunk/greenstone2/runtime-src/src/recpt/os_process_windows.h	(revision 22177)
@@ -38,18 +38,12 @@
 {
 public:
-  osprocesswindows(char* cmdline);
   osprocesswindows(char* cmdline, OSProcessPipeMode mode);
   virtual ~osprocesswindows();
-
-  /*
-  virtual bool eop();                  // end of pipe
-  virtual bool eop(OSProcessPipeMode); // end of pipe, for designated pipe
-  */
 
   virtual int read(char* buffer, const int buffer_len);
   virtual int write(const char* buffer, const int buffer_len);
 
-  virtual bool close();
-  virtual bool close(OSProcessPipeMode mode);
+  virtual bool close_write_pipe(OSProcessWarnStatus warn_status);
+  virtual bool close_read_pipe(OSProcessWarnStatus warn_status);
 
 protected:
