AGI - STDIO issue

Asterisk 1.2.13 Using Perl v5.8.6

I’ve written an AGI script in Perl.
I’m having an issue that is acting like the STDIO isn’t getting flushed to asterisk. My first Get Data call works perfectly, however everything after that involving the print"" to asterisk is ignored unless I put a sleep command after it. Without the sleep, it skips from the first Get Data to exiting the function (while performing all perl operations like the logging functions and print STDERR, but none of the Asterisk operations)

Verbose output at bottom

sub Per_Id(){
$| =1;
&log(“starting Fac_id”);
print “GET DATA 04_Enter_Per_ID 5000 10\n”;
my $buffer = ;
my $id = &checkresult($buffer);
&log(“ID: $id”);
&log(“Get Data Youve_Entered”);
print “STREAM FILE 10_Youve_Entered “” \n”;
&log(“Speak Digits”);
print “SAY DIGITS $id “”\n”;
sleep(3);
print “GET DATA 11_Is_Correct 5000 1\n”;
sleep(8);
$buffer = ;
my $correct = &checkresult($buffer);
&log(“Is Correct: $correct”);
&log(“End PerId”);
}

Notice the Playing Digits never finishes. It skips to another prompt, which skips to the end.
Verbose output
– uniqueid = 1163628915.1
– Playing ‘04_Enter_Facility_ID’ (language ‘en’)
PASS (25839974)
– Playing ‘digits/2’ (language ‘en’)
– Playing ‘digits/5’ (language ‘en’)
– Playing ‘digits/8’ (language ‘en’)
– Playing ‘digits/3’ (language ‘en’)
– Playing ‘digits/9’ (language ‘en’)
– Playing ‘11_Is_Correct’ (language ‘en’)
PASS (2)
– AGI Script facID.agi completed, returning 0

Without any of the sleep calls, here’s what happens:
I get the first prompt correctly (enter Id)
it logs the correct response.
Then I hear ("youve entered) correctly.
Then it exits the subroutine without playing anything in asterisk.

Verbose output
– uniqueid = 1163629525.4
– Playing ‘04_Enter_Facility_ID’ (language ‘en’)
PASS (258)
PASS (0)
– Playing ‘digits/2’ (language ‘en’)
– Playing ‘11_Is_Correct’ (language ‘en’)
– AGI Script aims.agi completed, returning 0
– Executing Playback(“IAX2/voicepulse01-1”, “/var/asterisk-1.2.13/sounds/vm-goodbye”) in new stack
– Playing ‘/var/asterisk-1.2.13/sounds/vm-goodbye’ (language ‘en’)
– Executing Hangup(“IAX2/voicepulse01-1”, “”) in new stack
== Spawn extension (aims, START, 3) exited non-zero on ‘IAX2/voicepulse01-1’
– Hungup ‘IAX2/voicepulse01-1’

Logfile output:
starting Fac_id,Time: 1163629544
ID: 258,Time: 1163629555
Get Data Youve_Entered,Time: 1163629555
Speak Digits,Time: 1163629555
Get Data Correct?,Time: 1163629555
Is Correct: 0,Time: 1163629557
End FacId,Time: 1163629557
EXIT,Time: 1163629557

Without being able to specifically tell you the cause for your issue, I can tell you that turning on AGI debug has helped me in lots of cases.
So just enter “agi debug” from the CLI and you will at least see what’s going on in detail.
From personal experience - why don’t you use fastAGI instead of StdIO?

With AGI Debug On:

The most obvious sign of something goofy going on is the say digits command. Even though it’s got a 6 digit number to read, it only reads the first and then it runs to the end without playing any additional prompts. Totally annoying, gotta find a way to make the perl script wait until Asterisk has executed it.

AGI Rx << GET DATA 04_Enter_Facility_ID 5000 10
– Playing ‘04_Enter_Facility_ID’ (language ‘en’)
AGI Tx >> 200 result=258963
PASS (258963)
AGI Rx << STREAM FILE 10_Youve_Entered ""
AGI Rx << SAY DIGITS 258963 “”
– Playing ‘digits/2’ (language ‘en’)
AGI Rx << GET DATA 11_Is_Correct 5000 1
– Playing ‘11_Is_Correct’ (language ‘en’)
AGI Tx >> 200 result=1
PASS (1)
– AGI Script facId.agi completed, returning 0
– Executing Playback(“IAX2/voicepulse01-1”, “vm-goodbye”) in new stack

Hey, why don’t you try using the Asterisk::AGI? It might be a lot easier for you :smile:

Looks cool, thanks for the pointer. But for my own edification if nothing else, I’d like to know how to handle the above. When the AGI language is moving at a different speed than asterisk…