Endil

Untitled

Nov 27th, 2015
116
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.95 KB | None | 0 0
  1. // 2.2. Есть ли данные на STDOUT дочернего процесса ?
  2.     BZERO(buf);
  3.  
  4.     if (0 == PeekNamedPipe(
  5.       read_stdout, buf, BUFSIZE - 1, &bread, &avail, NULL))
  6.     {
  7.       printf("\nPeekNamedPipe() fails with error: %i", GetLastError());
  8.       break;
  9.     }
  10.  
  11.     if (bread > 0)
  12.     {
  13.       // ReadFile() может прочитать меньше, чем есть в STDOUT дочернего
  14.       // процесса, необходимо организовать цикл, чтобы прочитать все данные.
  15.       left = bread;
  16.       idx  = 0;
  17.  
  18.       while (left > 0)
  19.       {
  20.         if (0 == (res = ReadFile(
  21.           read_stdout, &buf[idx], left, &received, NULL)))
  22.         {
  23.           printf("\nReadFile() fails with error: %i", GetLastError());
  24.           break;
  25.         }
  26.         if(res && (received == 0))
  27.           break; // EOF
  28.         left -= received;
  29.         idx  += received;
  30.       }
Advertisement
Add Comment
Please, Sign In to add comment