user23750
user23750

Reputation: 268

Exec function not working in AGI Script:

I am calling AGI SCRIPT from my dialplan and using exec function to call sh script but it is not working. Why ? Is it possible to call sh script using agi script ?

$agi->exec("sh count_length.sh '/SOUND/shakti.gsm'" );

Upvotes: 1

Views: 5695

Answers (1)

dougBTV
dougBTV

Reputation: 1878

Looks like you're using phpAGI

The exec function is to "execute" an Asterisk application when called as $agi->exec(). It's really intended to be used for a regular asterisk application, for example to playback a sound you would issue:

$agi->exec("Playback","demo-congrats");

From an Asterisk dialplan (not specifically through AGI) if you want to execute a system call, you use the SYSTEM application. Check out the help on it by issuing at the asterisk CLI:

asterisk*CLI> core show application System

But! I think what you're really going to want to do is shell out to your system using PHP's built-in methods of doing so. You'll get more finite control, and it's probably the most efficient way of doing it.

The way I typically do that is to use this function from the PHP manual page for system()

function syscall($command){
    if ($proc = popen("($command)2>&1","r")){
        while (!feof($proc)) $result .= fgets($proc, 1000);
        pclose($proc);
        return $result; 
        }
    }

Then you can call it like:

<?php
  $result = syscall("/path/to/count_length.sh '/SOUND/shakti.gsm'");
?>

Upvotes: 3

Related Questions