randallaw
asked on
How Perl run/call a cgi scripts and pass variable to the cgi scripts
Dear experts,
I have a cgi scripts which is write in python for send sms and locate at /usr/local/apache/cgi-bin/ sendsms
How can I use perl to run or call that cgi scripts?
I have try to do like this
sub sendsms()
{
$sendsms=`lynx -dump "http://www.xxxtesting.com:13013/cgi-bin/sendsms?&user=xxx&pass=xxx&from=&to=xxx&text=xxx"`;
print $sendsms;
}
if $text no spaceing it is OK but if $text has spaceing it has problems, and I think if we can replace spacing with a "+" sign it will also OK. Are there any methods can fix it or are there any BETTER methods?
Please help!
Thanks alot!
Randal
I have a cgi scripts which is write in python for send sms and locate at /usr/local/apache/cgi-bin/
How can I use perl to run or call that cgi scripts?
I have try to do like this
sub sendsms()
{
$sendsms=`lynx -dump "http://www.xxxtesting.com:13013/cgi-bin/sendsms?&user=xxx&pass=xxx&from=&to=xxx&text=xxx"`;
print $sendsms;
}
if $text no spaceing it is OK but if $text has spaceing it has problems, and I think if we can replace spacing with a "+" sign it will also OK. Are there any methods can fix it or are there any BETTER methods?
Please help!
Thanks alot!
Randal
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Just wonder, any other methods can call the cgi? It seem not a good method to run a cgi script by pass a command to the shell and run lynx?
Perl has a great library called LWP. It is basically a perl module you can use to get data from an HTTP server(you can get ftp and other stuff too)
here is a really simple way to use it(it can be MUCH more flexible and powerful)
---------------------
#!/usr/bin/perl
use LWP::Simple;
$url = 'http://www.xxxtesting.com:13013/cgi-bin/sendsms?&user=xxx&pass=xxx&from=&to=xxx&text=xxx'
$doc= get $url;
#eof.perl.file
thats it. it will post the data to the cgi script and grab whatever information comes back and store it in the $doc variable.
its pretty slick.
Seg
here is a really simple way to use it(it can be MUCH more flexible and powerful)
---------------------
#!/usr/bin/perl
use LWP::Simple;
$url = 'http://www.xxxtesting.com:13013/cgi-bin/sendsms?&user=xxx&pass=xxx&from=&to=xxx&text=xxx'
$doc= get $url;
#eof.perl.file
thats it. it will post the data to the cgi script and grab whatever information comes back and store it in the $doc variable.
its pretty slick.
Seg
$url =~ s/ /\%20/g;