Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 264
  • Last Modified:

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!

  • 2
1 Solution
surely. What you want to do is URLENCODE that url. There are a number of tools to do this.  Here is a quick one which will just replace the spaces with the +

lets say your URL is kept in a variable $url.

to replace all spaces with a + sign, you can do something like this.

$url =~ s/ /\+/g;

Perl is great about being able to do regular expression matching and replacing.  A really good start would be to read the perl regular expression POD.  perldoc perlre


Another (more correct?) substitution for spaces in urls is %20, so you would do:

$url =~ s/ /\%20/g;
randallawAuthor Commented:
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)


use LWP::Simple;

$url = 'http://www.xxxtesting.com:13013/cgi-bin/sendsms?&user=xxx&pass=xxx&from=&to=xxx&text=xxx'

$doc= get $url;


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.


Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now