Hi Lee,

I was following this thread with great interest. Is there somewhere a description how communication is defined in pbx? What commands are used and how are they structured? I personally don't know anything about asterisk but I am interested in this way of communicating between two apps.

Darius

----- Original Message ----- From: "Lee Jenkins" <[EMAIL PROTECTED]>
To: <lazarus@miraclec.com>
Sent: Saturday, December 30, 2006 3:49 PM
Subject: [lazarus] Console app problems



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.

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.

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

// 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

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

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

Reply via email to