浏览代码

Disregard incomplete line when PeekNamedPipe or ReadFile fails

An incomplete last line shouldn't be passed to the script, because it doesn't know the line is incomplete and may have trouble parsing it.

Also, the help says there is no further output after an error.
Jordan Russell 1 年之前
父节点
当前提交
47d882ac52
共有 1 个文件被更改,包括 11 次插入4 次删除
  1. 11 4
      Projects/Src/CmnFunc2.pas

+ 11 - 4
Projects/Src/CmnFunc2.pas

@@ -1770,8 +1770,10 @@ procedure TCreateProcessOutputReader.Read(const LastRead: Boolean);
       Pipe.OKToRead := PeekNamedPipe(Pipe.PipeRead, nil, 0, nil, @TotalBytesAvail, nil);
       Pipe.OKToRead := PeekNamedPipe(Pipe.PipeRead, nil, 0, nil, @TotalBytesAvail, nil);
       if not Pipe.OKToRead then begin
       if not Pipe.OKToRead then begin
         var LastError := GetLastError;
         var LastError := GetLastError;
-        if LastError <> ERROR_BROKEN_PIPE then
+        if LastError <> ERROR_BROKEN_PIPE then begin
+          Pipe.Buffer := '';
           HandleAndLogErrorFmt('PeekNamedPipe failed (%d).', [LastError]);
           HandleAndLogErrorFmt('PeekNamedPipe failed (%d).', [LastError]);
+        end;
       end else if TotalBytesAvail > 0 then begin
       end else if TotalBytesAvail > 0 then begin
         { Don't read more than our read limit }
         { Don't read more than our read limit }
         if TotalBytesAvail > FMaxTotalBytesToRead - FTotalBytesRead then
         if TotalBytesAvail > FMaxTotalBytesToRead - FTotalBytesRead then
@@ -1783,9 +1785,14 @@ procedure TCreateProcessOutputReader.Read(const LastRead: Boolean);
         Pipe.OKToRead := ReadFile(Pipe.PipeRead, Pipe.Buffer[TotalBytesHave+1],
         Pipe.OKToRead := ReadFile(Pipe.PipeRead, Pipe.Buffer[TotalBytesHave+1],
           TotalBytesAvail, BytesRead, nil);
           TotalBytesAvail, BytesRead, nil);
         if not Pipe.OKToRead then begin
         if not Pipe.OKToRead then begin
-          HandleAndLogErrorFmt('ReadFile failed (%d).', [GetLastError]);
-          { Restore back to original size }
-          SetLength(Pipe.Buffer, TotalBytesHave);
+          var LastError := GetLastError;
+          if LastError <> ERROR_BROKEN_PIPE then begin
+            Pipe.Buffer := '';
+            HandleAndLogErrorFmt('ReadFile failed (%d).', [LastError]);
+          end else begin
+            { Restore back to original size }
+            SetLength(Pipe.Buffer, TotalBytesHave);
+          end;
         end else begin
         end else begin
           { Correct length if less bytes were read than requested }
           { Correct length if less bytes were read than requested }
           SetLength(Pipe.Buffer, TotalBytesHave+BytesRead);
           SetLength(Pipe.Buffer, TotalBytesHave+BytesRead);