Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Using CGI exe with IW
#11
(09-12-2019, 08:34 AM)Alexandre Machado Wrote: If it requires the query_string to be mode=top, then you need to make sure it is before calling it.

You will need to modify the query_string yourself and make sure it matches the spec.

You are free to alter Request.QueryFields. It is just a TStringList which can be cleared and filled by you, before calling the CGIRunner
Hi, Alexandre,

I did what you said but the cgirunner is returning nothing and I still have the error of reply type. The code is below.
May you point me more some directions aboiut what is wrong? Is there some other way to debug it?

I just tried with a simple  "test.bat"  and a click sync of a iwbutton  using that file with this content:
Code:
@echo off echo Content-type: text/plain echo. echo. echo Hi ! echo Your IP ADDRESS is %REMOTE_ADDR% and your BROWSER is %HTTP_USER_AGENT%

Regards, Luiz


Code:
var
  CGIRunner: TIWCGIRunner;
  CGIModuleName: string;
  LFileName,s: string;
begin
  CGIModuleName := TIWAppInfo.GetAppPath + 'wwwroot\cgi-bin\newweb\test.bat';
  CGIRunner := TIWCGIRunner.Create;
  try
    // Set the name of the CGI module which runs our report
    CGIRunner.CGIModule := CGIModuleName;
    // WebApplication.Request.QueryFields.Add('mode=top');
    // call the CGI application
    CGIRunner.Execute(WebApplication, WebApplication.Request);
    // Check status result. Zero indicates success. Anything else is an error
    if CGIRunner.StatusResult = 0 then
    begin
     
      s:=CGIRunner.ResponseContent.Text;
      //Here CGIRunner.ResponseContent.Text is returning nothing
      
      with WebApplication.Response do
        begin
        ResetReplyType;
        Code := 200;
        ContentType := MIME_HTML;
        
        WriteString(s); //Here I get an AV about ReplyType already set
        end;


    end else
    begin
      WebApplication.ShowMessage('Error creating report: ' + CGIRunner.ErrorMessage);
    end;
  finally
    CGIRunner.Free;
  end;
end;
Reply
#12
Why that simple "test.bat" cgi doesn't work?
Reply
#13
Doesn't work?

Yes, it does work. Your test case exactly.


Attached Files
.zip   CGIRunner2.zip (Size: 52.96 KB / Downloads: 0)
Reply
#14
I have just published it on github

https://github.com/Atozed/IntraWeb/tree/...CGIRunner2
Reply
#15
(10-08-2019, 08:38 AM)Alexandre Machado Wrote: I have just published it on github

https://github.com/Atozed/IntraWeb/tree/...CGIRunner2
Thank you Alexandre,
This sample is working.
But I think there is a problem with your CGiRunner.
I am afraid you are not setting the working directory.
I have other CGI executable and I create my owner CGI runner from scratch.
If I don´t set the working directory in createprocess it doesn´t work.
If I set it, all works well.
This is because the cgi executable needs to run accessing others files in the folder directory.
If I don´t set the working dir, It can't find the files.

So, I suspect your IW CGI Runner is not setting the working Dir, because when I use it with a CGI exec that needs access other files in the folder, it doesn´t works.

In my createprocess I use something as next,  to set the working dir and all works well. I get it rid off, It doesn´t work.
Code:
CreateProcess(nil, PChar(CommandLine), @saSecurity, @saSecurity, true, CREATE_UNICODE_ENVIRONMENT, EnvBlock, WorkingDirP, suiStartup,
        piProcess);


Regards, Luiz
Reply
#16
I guess your CGI script, whatever it is, is buggy. If it takes for granted that the working directory is always its own directory, it should be changed.

I don't know any application which just tries to access the current directory as it was the application directory.

Imagine if IIS or a IW app would just serve a file from whatever directory is the current directory?
Reply
#17
Alexandre, the cgi is not mine. It is from an open source dicom library and it is used for many people in the comunity using dicom. It works without  problems with wamp and lamp. But don t work with intraweb. I believe its not bugged. As I said the working directory of cgi bin needs to be setted to work without problem. The cgi bin is not a security risk because it is where the cgi files are saved. I believe you need allow the developer set the working dir to CGI in iw cgi runner. If It was Buggy It did not work in wamp. If you want i can post the link to Conquest dicom software comunity.
Reply
#18
Because each CGI is its own process the working directory can easily be set when calling it. Its quite normal for CGI apps to expect the working directory to be the same as EXE, or if different to use it as the data dir.

Alexandre can't we just make it an option or even default during CreateProcess to set the working dir to a setting or default to the cgi exe location?
Reply
#19
(10-08-2019, 09:51 PM)kudzu Wrote: Because each CGI is its own process the working directory can easily be set when calling it. Its quite normal for CGI apps to expect the working directory to be the same as EXE, or if different to use it as the data dir.

Alexandre can't we just make it an option or even default during CreateProcess to set the working dir to a setting or default to the cgi exe location?
Thank you Kudzu.
I agree with you.
I am just trying to convince Alexandre about it.
Luiz
Reply
#20
I didn't say I would't do it. I just said that this is a feature request and not a bug.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)