On 12/30/06, Lee Jenkins <[EMAIL PROTECTED]> wrote:

Hi all,

I'm try to write a console application that interfaces with Asterisk
PBX.  The pbx communicates with the console application over stndin and
stdout.

Sorry for the question, but are you on the right library to use AGI ?


The problem that I'm having is that when I send a command using WriteLn,
the command doesn't return as it should so I'm wonder if FP/Laz handles
stdin/stdout in some way that I am not familiar with.

As far as I know (I will know more in this week btw :)), you should
also check STDERR.


Is the data written to WriteLn buffered or sent immediately?  Below is a
sample of the code I am trying.

It always buffered. Please take a look at
http://www.freepascal.org/docs-html/rtl/system/settextbuf.html


// Asterisk sends environmental vars at the start of the app
// over stdin.  When it's finished it sends a blank line.
Repeat;
    begin
    ReadLn(sRead);
    if (pos('uniqueid', sRead) >0) then
       sUniqueID := sRead;
    end;
until (sRead = '');


// -------------------------------------//
// Parameters Passed to app from Asterisk
// -------------------------------------//
// 1=DataToPlay, 2 = VoiceToUse
sData := paramstr(1);
sVoice := ParamStr(2);

// which voice to use?  If none specified use the default
if (FileExists(sData)) then
    begin
    // assume it's path to a text file.  Build Cmd line accordingly.
    sCmd := sExePath + '/swift -f ' + sData + ' -o /tmp/' + sUniqueID +
'.wav';
    sCmd := sCmd + '-p ' + sParams;
    end
else
    begin
    // assume that we are synthesizing the actual text provided in
parameter to app
    sCmd := sExePath + '/swift -o /tmp/' + sUniqueID + '.wav';
    sCmd := sCmd + ' -p ' + sParams + ' "'+ sData + '"';
    end;

Proc := TProcess.create(nil);
try
// Send command and write to file
Proc.CommandLine := sCmd;
Proc.Options := Proc.Options + [poWaitOnExit];
Proc.Execute;

// Write out command to play file to Asterisk over stdout
WriteLn('PLAYBACK /tmp/' + sUnique);
ReadLn(sCmd); // <===== Gets stuck here.  Does not return.

// finally, delete the file
Proc.Active := false;
Proc.CommandLine := 'rm -f /tmp/' + agi.UniqueID + '.wav';
Proc.Execute;

finally;
    Proc.free;
    end;


Thanks,

--

Warm Regards,

Lee



Ido
--
http://ik.homelinux.org/

_________________________________________________________________
    To unsubscribe: mail [EMAIL PROTECTED] with
               "unsubscribe" as the Subject
  archives at http://www.lazarus.freepascal.org/mailarchives

Reply via email to