Index: trunk/Ohana/src/opihi/pantasks/LocalJob.c
===================================================================
--- trunk/Ohana/src/opihi/pantasks/LocalJob.c	(revision 15031)
+++ trunk/Ohana/src/opihi/pantasks/LocalJob.c	(revision 15796)
@@ -15,10 +15,13 @@
 
   if ((job[0].state == JOB_EXIT) || (job[0].state == JOB_CRASH)) {
+    if (DEBUG) fprintf (stderr, "empty buffer 0: (%x) %d of %d\n", job[0].stdout_buff.buffer, job[0].stdout_buff.Nbuffer, job[0].stdout_buff.Nalloc); 
     EmptyIOBuffer (&job[0].stdout_buff, 10, job[0].stdout_fd);
     EmptyIOBuffer (&job[0].stderr_buff, 10, job[0].stderr_fd);
+    if (DEBUG) fprintf (stderr, "empty buffer 1: (%x) %d of %d\n", job[0].stdout_buff.buffer, job[0].stdout_buff.Nbuffer, job[0].stdout_buff.Nalloc); 
     close (job[0].stdout_fd);
     close (job[0].stderr_fd);
   } else {
     /* read stdout buffer */
+    if (DEBUG) fprintf (stderr, "read buffer 0: (%x) %d of %d\n", job[0].stdout_buff.buffer, job[0].stdout_buff.Nbuffer, job[0].stdout_buff.Nalloc); 
     while ((Nread = ReadtoIOBuffer (&job[0].stdout_buff, job[0].stdout_fd)) > 0);
     switch (Nread) {
@@ -32,4 +35,5 @@
 	break;
     }
+    if (DEBUG) fprintf (stderr, "read buffer 1: (%x) %d of %d\n", job[0].stdout_buff.buffer, job[0].stdout_buff.Nbuffer, job[0].stdout_buff.Nalloc); 
   
     /* read stderr buffer */
@@ -115,4 +119,6 @@
   if (pipe (stderr_fd) < 0) goto pipe_error;
 
+  // XXX nothing to be read at this point
+
   pid = fork ();
   if (!pid) { /* must be child process */
@@ -123,4 +129,10 @@
     close (stderr_fd[0]);
 
+    // XXX neither of these work to empty the child stdout buffer
+    // fflush (stdout);
+    // fflush (stderr);
+    // close (STDOUT_FILENO);
+    // close (STDERR_FILENO);
+
     /* tie our ends of the pipes to stdin, stdout, stderr */
     dup2 (stdout_fd[1], STDOUT_FILENO);
@@ -131,4 +143,7 @@
     setvbuf (stderr, (char *) NULL, _IONBF, BUFSIZ);
 
+    // XXX allow the parent time to read the stdout/stderr buffers
+    usleep (10000);
+
     status = execvp (job[0].argv[0], job[0].argv); 
     exit (1);
@@ -143,4 +158,19 @@
   fcntl (stdout_fd[0], F_SETFL, O_NONBLOCK);
   fcntl (stderr_fd[0], F_SETFL, O_NONBLOCK);
+
+  // XXX There seems to always be extra data on the pipe, specifically the 
+  // stdout buffer from the parent.  If I read it here, then it clears out that data.
+  // But, how can I be sure I will not start reading data from the exec-ed process?
+
+  { // test read of the stdout buffer
+    int Nread;
+    char buffer[0x1000];
+
+    Nread = read (stdout_fd[0], buffer, 0x1000);
+    if (DEBUG) fprintf (stderr, "read from stdout before exec: %d bytes\n", Nread);
+
+    Nread = read (stderr_fd[0], buffer, 0x1000);
+    if (DEBUG) fprintf (stderr, "read from stderr before exec: %d bytes\n", Nread);
+  }
 
   job[0].stdout_fd = stdout_fd[0];
