[fpc-pascal] Re: No access to Embedded FPC HTTP server on Vista orWin7

Graeme Geldenhuys graeme at geldenhuys.co.uk
Mon Oct 28 11:06:19 CET 2013




Regards,
  - Graeme -



On Monday 28/10/2013 at 11:38, Michael Van Canneyt  wrote:
> Damn windows Firewall :(

That's what I thought too... but maybe I was wrong. My bad!

> Does the request arrive at all in the webserver app ? i.e. does the 
> Accept() call return ?

For some reason I was concentrating on debugging the CGI client 
applications, thinking the problem is maybe there, or a Windows 
Firewall or Windows permission issue. After reading your reply I 
adding loads of debug log() lines in the webserver app, and it seems 
that the repeat...until loop that reads the TProcess output from the 
CGI app never exits.  Any ideas on why this is for Vista or Win7 OSes?


Here is the code that executes the CGI app, reads the CGI output and 
sends the Response content.

---------------------------

procedure TFPCustomCGIModule.ExecuteCGIApp(ARequest: TRequest;
    AResponse: TResponse; const ACGIApp: string);
const
  BufSize = 1024;
var
  p: TProcess;
  Buf: string;
  Count: integer;
  lResponse: string;
  i: integer;
begin
  Log('>> TFPCustomCGIModule.ExecuteCGIApp', lsDebug);
  p := TProcess.Create(nil);

  with p.Environment do
  begin
     // set lots of environment variables required for CGI 
applications to work
    ...snip...
  end;


  p.Options := [poUsePipes, poStdErrToOutPut, poNoConsole];
  p.ShowWindow := swoShowNormal;
  p.CurrentDirectory := ExtractFilePath(ACGIApp);
  p.CommandLine := ACGIApp + ' ' + ARequest.QueryString;
  try
    p.Execute;
    Log('p.Execute called', lsDebug);    //  <----  I see this is the 
log output, but nothing further...
    { Now process the output }
    lResponse := '';
    SetLength(Buf,BufSize);
    repeat
      if (p.Output<>nil) then
      begin
        Count := p.Output.Read(Buf[1],Length(Buf));
        lResponse := lResponse + Copy(Buf,1, Count);
      end
      else
        Count:=0;
    until Count=0;
    Log('repeat..until Count=0 returned', lsDebug);  //   <-----  
Under Vista and Win7 it never gets here??
    p.WaitOnExit;
    Log('p.WaitOnExit returned', lsDebug);
  finally
    p.Free;
    AResponse.Content := lResponse;
    AResponse.Code := p.ExitStatus;
    Log('About to do:  AResponse.SendContent', lsDebug);
    AResponse.SendContent;
    Log('Content successfully sent!', lsDebug);
    AResponse.ContentStream := nil;
  end;
  Log('<< TFPCustomCGIModule.ExecuteCGIApp', lsDebug);
end;
---------------------------


I'm using FPC 2.6.2 32-bit.  I'm going to compare my "reading console 
output" code to the code found in TIOStream class (which I only 
discovered a few days ago). Maybe that reveals something I'm doing 
wrong.


Regards,
  Graeme.

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.freepascal.org/pipermail/fpc-pascal/attachments/20131028/fc5600d5/attachment.html>


More information about the fpc-pascal mailing list