Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
Discussion Groups
General
GeneralPortable MacsHardwareNetworking
Applications
Mac ApplicationsEudoraFirefox / MozillaInternet ExplorerOutlook ExpressMS OfficeEntourageExcelPowerPointWordVirtual PCMedia PlayerOther MS Products
Programming
Mac ProgrammingCodeWarriorPerl
Country Specific
Australian Mac GroupUK Mac Group

Mac Forum / Programming / Perl / February 2007



Tip: Looking for answers? Try searching our database.

Running a PERL script from a PERL CGI

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Philippe de Rochambeau - 07 Feb 2007 22:33 GMT
Hello,

I would like to run a PERL script, which uses Net::FTP to retrieve a  
file and Mail::Sender to send it by email, from a PERL CGI.

Unfortunately, the second script never works  
("script_that_retrieves_a_file_by_ftp_and_sends_it_by_email.pl"  
below), probably because the CGI ends before the child script has had  
a chance to do anything.

Does anyone have any suggestions as to how I could make the CGI wait  
for the second script to complete?

Many thanks.

Philippe

#!/usr/bin/perl -w

use CGI qw/:standard/;

print header,
start_html('A Simple Example'),
h1('A Simple Example'),
start_form,
"What's your name? ",textfield('name'),p,
"What's the combination?", p,
checkbox_group(-name=>'words',
         -values=>['eenie','meenie','minie','moe'],
         -defaults=>['eenie','minie']), p,
"What's your favorite color? ",
popup_menu(-name=>'color',
     -values=>['red','green','blue','chartreuse']),p,
submit,
end_form,
hr;

if (param()) {
    my $ret = ` "perl  
script_that_retrieves_a_file_by_ftp_and_sends_it_by_email.pl" `;
    print "Returned code = ", ($ret >> 8), "<br>\n";
    print "Your name is",em(param('name')),p,
        "The keywords are: ",em(join(", ",param('words'))),p,
        "Your favorite color is ",em(param('color')),
        hr;
}
Sherm Pendley - 07 Feb 2007 23:48 GMT
> Hello,
>
[quoted text clipped - 8 lines]
> Does anyone have any suggestions as to how I could make the CGI  
> wait for the second script to complete?
...
>     my $ret = ` "perl  
> script_that_retrieves_a_file_by_ftp_and_sends_it_by_email.pl" `;

You are mistaken; the CGI cannot end before the child is finished.  
Backticks don't work that way, they cause Perl to wait until the  
called script is finished.

I suspect what's happening is that the script you're calling is doing  
something like forking its own child process to fetch and send the  
file in the background, and then returning immediately without  
waiting for that process to finish. When you run  
script_that_retrieves_etc from a shell prompt, does it return  
immediately?

sherm--

Web Hosting by West Virginians, for West Virginians: http://wv-www.net
Cocoa programming in Perl: http://camelbones.sourceforge.net
Ken Williams - 08 Feb 2007 03:19 GMT
> if (param()) {
>     my $ret = ` "perl  
> script_that_retrieves_a_file_by_ftp_and_sends_it_by_email.pl" `;

Try losing the double quotes.  Methinks that long-named script isn't  
even running.

 -Ken
Sherm Pendley - 08 Feb 2007 04:18 GMT
>> if (param()) {
>>     my $ret = ` "perl  
>> script_that_retrieves_a_file_by_ftp_and_sends_it_by_email.pl" `;
>
> Try losing the double quotes.  Methinks that long-named script  
> isn't even running.

Yes, definitely. I didn't mention that because I had assumed that  
they were there for illustrative purposes, but if they're not - ditch  
'em.

sherm--

Web Hosting by West Virginians, for West Virginians: http://wv-www.net
Cocoa programming in Perl: http://camelbones.sourceforge.net
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.