wbook has asked for the wisdom of the Perl Monks concerning the following question:

Dear monks. I have been helped by you before but is stuck again.

Components: [asterisk server] [fastagi server] [perlscript running on fastagi server] [bash script running a gawk-script]

Dataflow: [asterisk server] reads and writes data on stdin and stdout via [fastagi server] back and forth to the [perlscript]. This connection works ok.

When [asterisk server] communicates directly with the [bash script running a gawk-script] via the built-in asterisk agi-facility, the [bash script running a gawk-script] works ok. THE [..gawk-script] USES fflush() when it writes to stdout.

Problem: What I want is the [perlscript..] to call [..gawk-script] and data on stdin and stdout in the [..gawk-script] to pass through [perlscript...] and [fastagi server] to reach/be sent from [asterisk..].

From debuglines sent to files inside [..gawk-script] I know it is running but from the debug/trace-facility in [asterisk..] no sign of activity can bee seen.

The code is very straight forward and I thought this would be easy but having no knowledge of Perl I cannot deduce what the trouble might be. What I suspect is that I lack some (trivial) code to "pump" the data back and forth. I have consulted (amongst other sources) perlipc and perlopentut but faild. What is it in theese descriptions that I have so far faild to understand.

Thanks / Bertil

The code looks like this:

package MyAGI; use strict; use base 'Asterisk::FastAGI'; sub agi_handler { my $self = shift; use IPC::Open2; local (*READ, *WRITE); my $pid = open2(\*READ, \*WRITE, "/path/and/bashscript.sh"); #here I tried various ways to "pump" data via *READ and *WRITE but + without success waitpid( $pid, 0 ); } 1;

Replies are listed 'Best First'.
Re: Use of Open2()
by CountZero (Bishop) on Nov 22, 2009 at 14:21 UTC
    I do not have any of the hard-ware to test an Asterisk server on, but a quick search found the website of the author of asterisk-perl. Maybe you can find some more info there or by following the links on that page.

    CountZero

    A program should be light and agile, its subroutines connected like a string of pearls. The spirit and intent of the program should be retained throughout. There should be neither too little or too much, neither needless loops nor useless variables, neither lack of structure nor overwhelming rigidity." - The Tao of Programming, 4.1 - Geoffrey James

Revised: Use of Open2()
by wbook (Novice) on Nov 25, 2009 at 23:17 UTC

    Dear Monks and other seekers!

    This is my own reply to the previous questions entitled "Connect gawk via perl to fastagi and asterisk" and "Use of Open2()".

    After having looked near and far on the web I finally got back to where I started and must confess that my own question "what have I faild to understand" would better be phrased "what have I faild to read". When I consulted perlfoundations manual on IPC::Open2 closely and the concept of "bareword file handles" I saw an (of me) untested path and after trying I concluded it was the right one.

    The part of the script reading

    use IPC::Open2; local (*READ, *WRITE); my $pid = open2(\*READ, \*WRITE, "/path/and/bashscript.sh"); #here I tried various ways to "pump" data via *READ and *WRITE but + without success waitpid( $pid, 0 );

    should go like this

    use IPC::Open2; my $pid = open2(">&STDOUT", "<&STDIN", "/path/and/bashscript.sh"); #bashscript in its turn containing a gawk-script. waitpid( $pid, 0 );

    This solves my immediate problems. No "pumping" or otherwise is needed for the communication. It now appears to function correctly between both ends of the dataflow.

    Perl is without doubt a powerful language but there are many details to consider for the novice. Therfore I welcome all comments regarding its accuray or usefulness.

    Kind regards to you all / Bertil

      The knowledge you have gained through your own exertions, will be the most satisfying!

      CountZero

      A program should be light and agile, its subroutines connected like a string of pearls. The spirit and intent of the program should be retained throughout. There should be neither too little or too much, neither needless loops nor useless variables, neither lack of structure nor overwhelming rigidity." - The Tao of Programming, 4.1 - Geoffrey James