开发者

perl call to ruby script using backticks returns nothing

Ok, so I have a ruby script that grabs some data from FM Server and returns a tuple. I had to do this because there's no good perl FM module that I'm aware of.

[test.pl]

$ret = `ruby /root/rfm-query.rb $cid`;
@extens = split(/,/, $ret, 2);
print "DIAL SIP/$ex开发者_开发问答tens[0]";

So when I run this it will print "DIAL SIP/215" as expected but when using the same code in an Asterisk AGI script and using $extens[0] it always returns nothing.

#!/usr/bin/env perl
use Asterisk::AGI;
$|=1;

$AGI = new Asterisk::AGI;
%input = $AGI->ReadParse();

$cid = substr $input{'callerid'}, 1;
$cid =~ s/\+//g;

$ret = `ruby /root/rfm-query.rb $cid`; #rets nothing
@extens = split(/,/, $ret, 2);

$AGI->exec("DIAL SIP/$extens[0]");

Why does it work in a test script but not in an AGI?


I'm not sure what an Asterix AGI script is, but if its anything like CGI, where your code is being run by a server, then its probably running as a different user as you. Hopefully it is and not root and it probably can't read /root/rfm-query.rb.

You can check this by trying to open and print the file for reading.

my $rfm_query_file = "/root/rfm-query.rb";
open my $fh, "<", $rfm_query_file or die "Cant open $rfm_query_file: $!";

(Also, shame on you if you're developing and testing code as root.)

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜