diff --git a/SystemInformation.cxx b/SystemInformation.cxx
index 0460b2906fbf7d71e65936ec11d2a9823ab39c70..744d5ecf6765e42d0ccf59e0cffc196a4f287d29 100644
--- a/SystemInformation.cxx
+++ b/SystemInformation.cxx
@@ -4059,8 +4059,10 @@ kwsys_stl::string SystemInformationImplementation::RunProcess(kwsys_stl::vector<
   char* data = NULL;
   int length;
   double timeout = 255;
+  int pipe; // pipe id as returned by kwsysProcess_WaitForData()
 
-  while(kwsysProcess_WaitForData(gp,&data,&length,&timeout)) // wait for 1s
+  while( ( pipe = kwsysProcess_WaitForData(gp,&data,&length,&timeout),
+           (pipe == kwsysProcess_Pipe_STDOUT || pipe == kwsysProcess_Pipe_STDERR) ) ) // wait for 1s
     {
     for(int i=0;i<length;i++)
       {