Hi Everyone, I'm wondering if anyone here write AGI's in compiled binaries. I'm writing a small Cepstral AGI in Freepascal/Lazarus. I know there are some other AGI's out there, but I wanted to add some more functionality than what is available such as having the AGI determine if the "data" argument is plain text or a path to a text file and act accordingly. The problem that I'm having is that Asterisk is not sending back any responses to commands. I'm using stdin/stdout through the ReadLn and WriteLn commands in freepascal. Reading in the initial env variables is no problem, but once I issue a command like so: // >>> Create wav file from swift here <<< WriteLn('EXEC PLAYBACK /tmp/NewlyCreatedFile'); ReadLn(StringVar); // <========= Never returns // >>> Clean up code to delete file, etc <<< (The command STREAM FILES always comes back and complains the file is not found when it really is there so I have settled for using the Playback application.) Am I mistaken in thinking that Asterisk is supposed to send back a response over stdin? Of course, if I do not attempt to read the response, I run into bigger problem as the sound file will not be found because the next portion of code deletes the file created for playback, but before asterisk has a chance to play it! I worked on this thing all day yesterday and tried everything that I can think of, but this morning I figured I will ask for some help. -- Warm Regards, Lee
use "agi debug" command from the Asterisk CLI to see what is going on. Also, the last time I checked, "\n" is needed at the end of any command sent to Asterisk. Regards. On 12/29/06, Lee Jenkins <lee@datatrakpos.com> wrote:> > Hi Everyone, > > I'm wondering if anyone here write AGI's in compiled binaries. I'm > writing a small Cepstral AGI in Freepascal/Lazarus. I know there are > some other AGI's out there, but I wanted to add some more functionality > than what is available such as having the AGI determine if the "data" > argument is plain text or a path to a text file and act accordingly. > > The problem that I'm having is that Asterisk is not sending back any > responses to commands. I'm using stdin/stdout through the ReadLn and > WriteLn commands in freepascal. > > Reading in the initial env variables is no problem, but once I issue a > command like so: > > // >>> Create wav file from swift here <<< > > WriteLn('EXEC PLAYBACK /tmp/NewlyCreatedFile'); > > ReadLn(StringVar); // <========= Never returns > > // >>> Clean up code to delete file, etc <<< > > > (The command STREAM FILES always comes back and complains the file is > not found when it really is there so I have settled for using the > Playback application.) > > Am I mistaken in thinking that Asterisk is supposed to send back a > response over stdin? > > Of course, if I do not attempt to read the response, I run into bigger > problem as the sound file will not be found because the next portion of > code deletes the file created for playback, but before asterisk has a > chance to play it! > > I worked on this thing all day yesterday and tried everything that I can > think of, but this morning I figured I will ask for some help. > -- > > Warm Regards, > > Lee > > _______________________________________________ > --Bandwidth and Colocation provided by Easynews.com -- > > asterisk-users mailing list > To UNSUBSCRIBE or update options visit: > http://lists.digium.com/mailman/listinfo/asterisk-users >-- "Su nombre es GNU/Linux, no solamente Linux, mas info en http://www.gnu.org"
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