Results 1 to 5 of 5
Hi all,
I'm stuck with how to pass the return value to asterisk. That is, a value has to be passed from perl script to asterisk. The variable returned in ...
- 10-15-2007 #1Just Joined!
- Join Date
- Sep 2007
- Posts
- 3
Return value from Perl
Hi all,
I'm stuck with how to pass the return value to asterisk. That is, a value has to be passed from perl script to asterisk. The variable returned in Perl has to be passed to asterisk, where if the return value is 1 from perl , i have to do something and if return value is 0, i have to do something else.
I have written code like this.
exten => 9999,23,AGI(insert_into_database.pl|${intime}|${ou ttime}|${telephone_number}|${date}|${month}|${year }
in Perl Script:
******************
$fullDate = $ARGV[3]."".SARGV[4]."".$ARGV[5];
...........
........(some more code)
if($record == 0 && $rec == 0 && $pri == 0)
{
$stmt = "INSERT into $table_name values($ARGV[0],$ARGV[1],$ARGV[2],$fullDate)";
$fetch = $dbh->prepare($stmt);
$fetch->execute();
}
else
{
print "\nValues cannot be inserted in database\n\n";
}
If that "if" condition satisfies, then it has to return some value, say 0.Otherwise 1. Even if i write return 0, there in "if" condition, how can i get that value to asterisk?
Pls suggest me how to proceed.
Thanks in advance,
Padmaja T N.
- 10-15-2007 #2
I don't know anything about asterisk, but you've asked this question in forums all over the web, and none of the answers seem to help you.
Have you tried this in your Perl script?
orCode:exit(0);
Code:exit(1);
- 10-15-2007 #3Just Joined!
- Join Date
- Sep 2007
- Posts
- 3
Hi,
Thanks for responding. Its not working, i've tried it earlier .
Pls suggest me how to proceed further.
- 10-15-2007 #4
Not knowing anything about asterisk, I shouldn't try to guess further.
But I notice that you've asked the question here. That's good, because asterisk.org is probably the only place you'll get an answer.
In that thread, when a user gave you an answer, you said:
"Could not find any solution" does not help someone help you. Be specific. In that forum, say exactly what you did (including snippets of Perl code when that is relevant) and exactly what error messages you got back. Don't paraphrase the error messages; copy and paste them into that forum on asterisk.org. Otherwise they won't know what your problem is.I have tried that also. But could not find any solution.
Good luck.
- 10-15-2007 #5
This depends on how asterisk works. I do not know asterisk, so I will use Bash to illustrate what I mean.
There are two ways for a process to communicate with a child without somehow directly communicating (be it over FIFOs, sockets, or whatever). These are by capturing output and by checking return value.
What do I mean? Well, let us say that I have the following Perl script:
This script checks to see whether it was given any arguments. If it does have arguments, it prints "1", otherwise it prints "0". How does this help? Well, imagine this Bash script:Code:#!/usr/bin/perl # This script's name is: communicate_by_output.pl if(@ARGV) { print "1"; } else { print "0"; }
This Bash script executes the above Perl script, and captures its output. It then checks the output to see if it was 0 or 1, and responds appropriately. Here, I could have printed anything I wanted from the Perl script, but in general, you want something very simple, not a long string, because it makes it harder to make mistakes in copying.Code:#!/bin/bash # This script's name is: capture_output.sh output=$(./communicate_by_output) if [ "$output" = "1" ]; then echo "My child told me 1!"; elif [ "$output" = "0" ]; then echo "My child told me 0!"; fi
Now, that was communicating through output. Now let us imagine the following pair (that does the same thing as the above pair). These will communicate by return value.
Code:#!/usr/bin/perl # This script's name is: communicate_by_return.pl if(@ARGV) { exit 1; } else { exit 0; }In this case, the Perl script exits with return status of 1 if it was given arguments, and 0 if it wasn't. In Bash, I check $? (which contains the return value of the last executed program), and do something based on what the return value was.Code:#!/bin/bash # This script's name is: capture_return.sh ./communicate_by_output retval=$? if [ "$retval" = "1" ]; then echo "My child told me 1!"; elif [ "$retval" = "0" ]; then echo "My child told me 0!"; fi
I should note that in general, a return value of "0" means "everything went okay", and anything else means "a problem occurred".
Now, I don't know how to implement one of these in asterisk. However, these are probably the most likely methods you'll find.DISTRO=Arch
Registered Linux User #388732


Reply With Quote