?
Solved

How Perl run/call a cgi scripts and pass variable to the cgi scripts

Posted on 2003-03-17
4
Medium Priority
?
258 Views
Last Modified: 2010-03-05
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
0
Comment
Question by:randallaw
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
4 Comments
 
LVL 2

Accepted Solution

by:
SegFault earned 90 total points
ID: 8152113
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

hth

Seg
0
 
LVL 26

Expert Comment

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

$url =~ s/ /\%20/g;
0
 

Author Comment

by:randallaw
ID: 8157840
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?
0
 
LVL 2

Expert Comment

by:SegFault
ID: 8158039
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
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I've just discovered very important differences between Windows an Unix formats in Perl,at least 5.xx.. MOST IMPORTANT: Use Unix file format while saving Your script. otherwise it will have ^M s or smth likely weird in the EOL, Then DO NOT use m…
Checking the Alert Log in AWS RDS Oracle can be a pain through their user interface.  I made a script to download the Alert Log, look for errors, and email me the trace files.  In this article I'll describe what I did and share my script.
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
Six Sigma Control Plans

777 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question