Browse Source

Bug fix: GUI freezes while executing an extension with ShowResultsInMsgBox or CopyResults flags

Source commit: 9ae2cbd61b1dc81797323b363f8972aff7130a6a
Martin Prikryl 7 years ago
parent
commit
efe30f95dd
1 changed files with 12 additions and 4 deletions
  1. 12 4
      source/windows/Tools.cpp

+ 12 - 4
source/windows/Tools.cpp

@@ -369,11 +369,19 @@ static void __fastcall ExecuteProcessAndReadOutput(const
         CloseHandle(PipeWrite);
       }
 
-      char Buffer[4096];
-      DWORD BytesRead;
-      while (ReadFile(PipeRead, Buffer, sizeof(Buffer), &BytesRead, NULL))
+      DWORD BytesAvail;
+      while (PeekNamedPipe(PipeRead, NULL, 0, NULL, &BytesAvail, NULL))
       {
-        Output += UnicodeString(UTF8String(Buffer, BytesRead));
+        if (BytesAvail > 0)
+        {
+          char Buffer[4096];
+          DWORD BytesToRead = std::min(BytesAvail, static_cast<unsigned long>(sizeof(Buffer)));
+          DWORD BytesRead;
+          if (ReadFile(PipeRead, Buffer, BytesToRead, &BytesRead, NULL))
+          {
+            Output += UnicodeString(UTF8String(Buffer, BytesRead));
+          }
+        }
         // Same as in ExecuteShellCheckedAndWait
         Sleep(200);
         Application->ProcessMessages();