diff src/dirfns.cc @ 3147:894d516b4a00

[project @ 1998-02-06 06:00:08 by jwe]
author jwe
date Fri, 06 Feb 1998 06:00:10 +0000
parents 38de16594cb4
children 02866242d3ae
line wrap: on
line diff
--- a/src/dirfns.cc	Thu Feb 05 20:59:48 1998 +0000
+++ b/src/dirfns.cc	Fri Feb 06 06:00:10 1998 +0000
@@ -155,11 +155,33 @@
 
   unwind_protect::add (cleanup_iprocstream, cmd);
 
+  // XXX FIXME XXX -- sometimes, the subprocess hasn't written
+  // anything before we try to read from the procstream.  The kluge
+  // below (simply waiting and trying again) is ugly, but it seems to
+  // work, at least most of the time.  It could probably still fail if
+  // the subprocess hasn't started writing after the snooze.  Isn't
+  // there a better way?  If there is, you should also fix the code
+  // for the system function in toplev.cc.
+
   if (cmd && *cmd)
     {
-      int ch;
-      while ((ch = cmd->get ()) != EOF)
-	octave_stdout << (char) ch;
+      char ch;
+
+      if (cmd->get (ch))
+        octave_stdout << ch;
+      else
+        {
+          cmd->clear ();
+
+#if defined (HAVE_USLEEP)
+          usleep (100);
+#else
+          sleep (1);
+#endif
+        }
+
+      while (cmd->get (ch))
+        octave_stdout << ch;
     }
   else
     error ("couldn't start process for ls!");