[asterisk-users] Binary AGI Scripts

Lee Jenkins lee at datatrakpos.com
Sat Dec 30 10:16:55 MST 2006


Lee Jenkins wrote:
> 

Hi all, after trying a number of different ways to get this to work, I 
have found a way.

For some reason, it does not appear to me that using standard Writeln() 
to send commands to Asterisk are ignored for some reason, even when 
appending #10 or #13#10 or #13 to the end.

At any rate, see following the example here:

http://www.freepascal.org/docs-html/rtl/system/flush.html

I create explicit file association with stdout:

var
F: Text;
sRead, sRet: string;
begin
repeat;
    begin
    Readln(sRead);
    // other assign values as needed
    end;
until (sRead = '');

Assign(F,'');
Rewrite(F);
Write('NOOP Here is some sample output to CLI' + #10);
Flush(F);
ReadLn(sRet);

Close(f);
end;

This works.  One thing that I ran across was that if I also tried to use 
ReadLn using the explicit F file variable, I got an AV.

So it seems (at least for me and my particular setup) that ReadLn reads 
ok with Asterisk, but an explicit control over stdout must be used with 
explicit flush()'s to ensure that Asterisk gets the ouputted command.

Keep in mind that I am not debugging my app in real time.  I'm compiling 
it on a VMWare linux image on my windows box and then copying it over to 
my asterisk linux box.  Just been using a lot of file logging to see 
what's going on under the hood when the app runs and this is what 
appears to be the problem, especially taking into account that the 
following simple program does not work:

var
sRead, sRet: string;
begin
repeat;
    begin
    Readln(sRead);
    // other assign values as needed
    end;
until (sRead = '');

Writeln('NOOP Here is some sample output to CLI' + #10); // nope
// Writeln('NOOP Here is some sample output to CLI'); // Nope
// Writeln('NOOP Here is some sample output to CLI' + #13#10); //Nope
// Writeln('NOOP Here is some sample output to CLI' + #13); //nope

ReadLn(sRet);  // <======= Hangs here

Close(f);
end;

Thanks for the responses.

-- 

Warm Regards,

Lee



More information about the asterisk-users mailing list