Subversion Repositories fastphp

Rev

Rev 40 | Rev 42 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 40 Rev 41
Line 51... Line 51...
51
  WorkDir: string;
51
  WorkDir: string;
52
  Handle: Boolean;
52
  Handle: Boolean;
53
  testString: AnsiString;
53
  testString: AnsiString;
54
  CommandLine: string;
54
  CommandLine: string;
55
  Output, OutputLastCache: string;
55
  Output, OutputLastCache: string;
-
 
56
const
-
 
57
  SIGNAL_END_OF_TRANSMISSION = #1#2#3#4#5#6#7#8;
-
 
58
  SIGNAL_TERMINATE           = #8#7#6#5#4#3#2#1;
56
begin
59
begin
57
  if Self.WorkDir = '' then
60
  if Self.WorkDir = '' then
58
    WorkDir := ExtractFilePath(ParamStr(0))
61
    WorkDir := ExtractFilePath(ParamStr(0))
59
  else
62
  else
60
    WorkDir := Self.WorkDir;
63
    WorkDir := Self.WorkDir;
Line 110... Line 113...
110
            WriteFile(StdInPipeWrite, FInputWaiting[1], Length(FInputWaiting), BytesWritten, nil);
113
            WriteFile(StdInPipeWrite, FInputWaiting[1], Length(FInputWaiting), BytesWritten, nil);
111
          end;
114
          end;
112
          {$ENDREGION}
115
          {$ENDREGION}
113
 
116
 
114
          {$REGION 'Terminate input sequence'}
117
          {$REGION 'Terminate input sequence'}
115
          testString := #13#10#1#2#3#4#5#6#7#8#13#10;
118
          testString := #13#10+SIGNAL_END_OF_TRANSMISSION+#13#10;
116
          WriteFile(StdInPipeWrite, testString[1], Length(testString), BytesWritten, nil);
119
          WriteFile(StdInPipeWrite, testString[1], Length(testString), BytesWritten, nil);
117
          {$ENDREGION}
120
          {$ENDREGION}
118
 
121
 
119
          {$REGION 'Gather output'}
122
          {$REGION 'Gather output'}
120
          Output := '';
123
          Output := '';
Line 122... Line 125...
122
            WasOK := ReadFile(StdOutPipeRead, Buffer, 255, BytesRead, nil);
125
            WasOK := ReadFile(StdOutPipeRead, Buffer, 255, BytesRead, nil);
123
            if BytesRead > 0 then
126
            if BytesRead > 0 then
124
            begin
127
            begin
125
              Buffer[BytesRead] := #0;
128
              Buffer[BytesRead] := #0;
126
              Output := Output + Buffer;
129
              Output := Output + Buffer;
127
              if Pos(#1#2#3#4#5#6#7#8, Output) >= 1 then
130
              if Pos(SIGNAL_END_OF_TRANSMISSION, Output) >= 1 then
128
              begin
131
              begin
129
                Output := StringReplace(Output, #1#2#3#4#5#6#7#8, '', []);
132
                Output := StringReplace(Output, SIGNAL_END_OF_TRANSMISSION, '', []);
130
                break;
133
                break;
131
              end;
134
              end;
132
            end;
135
            end;
133
          until not WasOK or (BytesRead = 0) or Self.Terminated or not ProcessRunning(PI);
136
          until not WasOK or (BytesRead = 0) or Self.Terminated or not ProcessRunning(PI);
134
          {$ENDREGION}
137
          {$ENDREGION}
Line 144... Line 147...
144
            end;
147
            end;
145
          end;
148
          end;
146
          {$ENDREGION}
149
          {$ENDREGION}
147
        end;
150
        end;
148
 
151
 
149
        CloseHandle(StdInPipeWrite);
152
        // Signal the code explorer to terminate
-
 
153
        testString := #13#10+SIGNAL_TERMINATE+#13#10;
150
        TerminateProcess(pi.hProcess, 0);  // TODO: for some reason, after closing the editor, php.exe keeps running in the task list
154
        WriteFile(StdInPipeWrite, testString[1], Length(testString), BytesWritten, nil);
151
        WaitForSingleObject(PI.hProcess, INFINITE);
155
        WaitForSingleObject(PI.hProcess, INFINITE);
-
 
156
 
-
 
157
        CloseHandle(StdInPipeWrite);
152
      finally
158
      finally
153
        CloseHandle(PI.hThread);
159
        CloseHandle(PI.hThread);
154
        CloseHandle(PI.hProcess);
160
        CloseHandle(PI.hProcess);
155
      end;
161
      end;
156
  finally
162
  finally