freeswitch/scripts/socket/fs.pl
Anthony Minessale d1d1c73390 get fs.pl up to date
git-svn-id: http://svn.freeswitch.org/svn/freeswitch/trunk@4140 d0543943-73ff-0310-b7d9-9358b9ac24b2
2007-02-06 21:24:43 +00:00

58 lines
1.1 KiB
Perl
Raw Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

use FreeSWITCH::Client;
use Data::Dumper;
use Term::ReadLine;
my $password = "ClueCon";
my $fs = init FreeSWITCH::Client {-password => $password} or die "Error $@";
my $term = new Term::ReadLine "FreeSWITCH CLI";
my $prompt = "FreeSWITCH>";
my $OUT = $term->OUT .. \*STDOUT;
my $pid;
my $log = shift;
$SIG{CHLD} = sub {$fs->disconnect(); die "done"};
if ($log) {
$pid = fork;
if (!$pid) {
my $fs2 = init FreeSWITCH::Client {-password => $password} or die "Error $@";
$fs2->sendmsg({ 'command' => "log $log" });
while (1) {
my $reply = $fs2->readhash(undef);
if ($reply->{socketerror}) {
die "socket error";
}
if ($reply->{body}) {
print $reply->{body};
}
}
exit;
}
}
while ( defined ($_ = $term->readline($prompt)) ) {
if ($_) {
if ($_ =~ /exit/) {
last;
}
my $reply = $fs->command($_);
if ($reply->{socketerror}) {
$fs2->disconnect();
die "socket error";
}
print "$reply\n";
}
$term->addhistory($_) if /\S/;
}
if ($pid) {
kill 9 => $pid;
}