Running a PERL script from a PERL CGI

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;
}

0
phiroc
2/7/2007 10:33:29 PM
perl.macosx 2309 articles. 0 followers. Follow

3 Replies
3181 Views

Similar Articles

[PageSpeed] 15

On Feb 7, 2007, at 5:33 PM, Philippe de Rochambeau wrote:

> 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?
....
> 	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


0
sherm
2/7/2007 11:48:18 PM
On Feb 7, 2007, at 4:33 PM, Philippe de Rochambeau wrote:

> 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

0
ken
2/8/2007 3:19:22 AM
On Feb 7, 2007, at 10:19 PM, Ken Williams wrote:

> On Feb 7, 2007, at 4:33 PM, Philippe de Rochambeau wrote:
>
>> 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


0
sherm
2/8/2007 4:18:10 AM
Reply:

Similar Artilces:

cgi script that takes in data then runs script on different host
Hi All, I've got a cgi form that takes in data. Then, I want the data to be passed to a script that's waiting on a DIFFERENT host. So, say I have this pseudo-code: cgi script on host 1 pass $name to host 2 script on host 2 # get $name ---------------------------> print "hi there $name!\n"; Obviously, I'll be doing something a little more in-depth than printing the variables, but you get the idea! I went through perlfaq 8 in the perldocs, but I didn't understand the networking jargon :-( Thanks! Simon ===== #####...

running cgi script
It's been a long time since I tried to work with cgi scripting, & I never did learn a whole lot about cgi. I'm trying to run a simple script straight out of the Perl Black Book to display the CGI environment hash to the web browser screen (I'll want to do other things with it later, but thought I'd start with this). This is on a Sun Solaris, running Netscape webserver if that matters. Here's the script: #!/usr/local/bin/perl use CGI; $co = new CGI; print $co->header, $co->start_html('Test Environment'), $co->ce...

How to run cgi script
------_=_NextPart_001_01C90C44.AEA1359F Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable Hi, =20 I have installed IIS on my machine (to make my machine web server). Now i need to execute / run cgi script on my machine. cgi script is saved in c:\irfan. =20 now how should i run this cgi script in web browser. which webURL i should give. =20 Regards Irfan. =20 ------_=_NextPart_001_01C90C44.AEA1359F-- Irfan J Sayed (isayed) wrote: > Hi, > > I have installed IIS on my machine (to make my machine web server). Now...

Referring to a cgi script within a cgi script.
--=====================_16295211==_.ALT Content-Type: text/plain; charset="us-ascii"; format=flowed Hello all, This is my first post, so bear with me. I have a form that activates a cgi script that scans a flat-file *.csv file, matches on a unique identifier, identifies the line that contains the identifier, and pushes the separated values of that line into an array. I want to pass those values into another (second) cgi script, but I don't know how. I made the original script display the values of the line in "text" input boxes in a web page the ...

cgi scripts are not running
i have installed bugzilla, but my cgi scripts are not running properly, whether its problem in apache or execcgi, plz post ur valuable suggestions On Mon, Dec 12, 2005 at 03:51:45AM -0800, sid wrote: > i have installed bugzilla, but my cgi scripts are not running properly, > whether its problem in apache or execcgi, plz post ur valuable > suggestions Follow the installation instructions. Read the errorlog of apache. Tell us what you did. -- Regards, Olav Without more information, it's difficult to help. What does checksetup.pl tell you? What does testserver...

running a Java Script from a CGI
This is a snip of code i have in a CGI. I am having trouble getting ANY java script to run from within a CGI. I would appreciate some help with why this isn't running right. I have looked on the web (do a search on google with java in the box, hahaha) for a good resource to help me figure out how to run other Java Scripts from within a CGI help with finding one would be appreciated. if ($query->param('list_name') eq 'Star Wars Galaxies') { <Head> <SCRIPT LANGUAGE="JavaScript"> function NewWindow(mypage, myname, w, h, scroll) {...

Cannot run my first CGI-script
Hi, I am trying to run my first CGI-script on my remote host. The script have been taken from Ovid guide - http://www.easystreet.com/~ovid/cgi_course/index.html and should provide output of errors to the browser (IE 5.0 or Netscape), but besides annoying 500 Internal Server mistake I could not get anything, after trying it's url in browser (http://208.56.78.155/cgi-bin/time.cgi ); #!usr/bin/perl -wT BEGIN { $|=1; print "Content-type: text/html\n\n"; use CGI::Carp qw(fatalsToBrowser); } use strict; use diagnostics; use CGI; my $query = new CGI; ...

Cant run CGI Scripts?
------=_NextPart_000_00E3_01C1889B.9EFA5980 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable Sorry for the 'newbie' question, but I am going bald from pulling my = hair out, so I had to ask some people with brains... I am trying to run a CGI script on an Intranet. Basically the user = opens a form in the intranet and when they submit it a modified copy (ie = slightly different layout) is sent to someone (offsite) and the info in = the form is saved to a text file. I have written all the code, but I = cannot get the ...

Unable to run cgi script
I am trying to set my system up as a Webserver for testing purposes System is SuSe 8.1 stand-a-lone Apache 1.3 Have got Apache running OK and tested it in standalone mode using http://localhost which shows the appropriate test page I have configured httpd.config to point to my directories as follows ScriptAlias /cgi-bin/=A0=A0/home/kelvin/cgi-bin/ <Directory /home/kelvin/cgi-bin> Options +ExecCGI AddHandler cgi-script cgi pl=20 </Directory> I am now trying to run simple html & perl scripts as shown below <html><head> <title>My test pa...

Running a CGI script as root
Hello, I need to write a CGI script able to launch, from an Intranet Web page, an executable on my Linux RH. To do that I need to run the executable as root because it works fine only if I've got root's privileges. The problem is: I cannot do that. Could anyone gives me any help? Thank you Paolo Hello, I don't understand why you need to be root, I would suggest finding another means, for security reasons. Can you explain a little more about this? That said, here is one way you can do it : Have you seen the sudo command? You can give root access to spec...

Re: Cgi scripts not running...
Chris, > I am working within a small network (10 computers). I am trying to > create a form that people can access through the f: (global drive). They > will fill in this form, and the results will be processed by my script, and > emailed to me. I have installed activeperl in the f drivebut I cannot seem > to get any scripts to run in the intranet...any suggestions? We are running > Netware 4.11 as the server. Is the computer that runs the scripts (on f: drive) the server? Is it a file-server or a web-server? (It needs to be a web-server). When you view...

yield the running of current window script to allow to run other windows script
Hello, I have two windows opened.I would like to suspend the runing of one window script so that other window script can be run.I am just wondeing is there any way to do the same. Thanks, Sri. Yield(); On May 20, 7:06=A0am, sr.100...@gmail.com wrote: > Hello, > > =A0 I have two windows opened.I would like to suspend the runing of one > window script so that other window script can be run.I am just > wondeing is there any way to do the same. > > Thanks, > Sri. ...

Problem Running CGI Scripts in PWS
Hello: I am running the latest version of Active Perl on a Windows 98 platform as a development environment. I have installed and set up PWS. I have modified "Scripts" in the Windows registry to run .PLX files from perl\bin (c:\perl\bin\perl.exe %s %s) and I have set associations for .pl, ..plx and .cgi files using "My Computer\View\Folder Options". The production web site is on a Unix box. When I run the dev web pages in IE (using http://localhost/), (note: "localhost" is C:\inetpub\wwwroot) everything is fine until the cgi script is called...

Running Inline::Python in a CGI script
I'm trying to use Inline::Python within a CGI script. The script is run under the latest version of Webmin's miniserv.pl web server. I have written two very variations of a very simple script. 1. The first version embeds a couple of Python functions in the DATA portion of the Perl cgi. This version executes fine both from the cli and as a cgi. 2.The second version imports a class from a Python module. The script runs fine when called from the cli. However, it borks when executed as a cgi, complaining of calls to undefined functions/methods. Of course, those functions/met...

ORA-01017 ... but only when script is run as CGI
I'm using current versions of DBI and DBD::Oracle in a CGI script, Oracle 10.2 client talking to an Oracle 9 database, RedHat Linux. The script previously ran successfully on a similar machine with the Oracle 9 client. I have a simple test script, in which the username, password and SID are hardcoded. If I run this script from the command line, it connects without problems. If I call the script as a CGI script, I get ORA-01017 in OCISessionBegin, which is the bad username or password error. As far as I can tell, environment variables are the same in both contexts, the same t...

Web resources about - Running a PERL script from a PERL CGI - perl.macosx

Running - Wikipedia, the free encyclopedia
This article is about the type of locomotion in humans. For running in horses, see Horse gait . For locomotion in dogs, see Gait (dog) . For ...

Missing Sunshine Coast swimmer running from police
A man missing after diving into the surf at a Sunshine Coast beach in the early hours of Saturday was fleeing police, it has been revealed.

Court retirements have hopefuls off and running
Court retirements have hopefuls off and running The Augusta Chronicle Richmond County State Court Judge John Flythe will run for the judgeship ...

Running headless Selenium WebDriver tests in Docker containers
... official ‘docker run’ documentation has lots of details. One other thing I found useful for troubleshooting Selenium WebDriver scripts running ...

The craziest 'party' I went to at CES had me riding through Vegas in the back of an armored truck and ...
Every year, the Consumer Electronics Conference in Las Vegas gives tech companies a chance to make announcements and flash their latest gadgets ...

Biden regrets not running for president 'every day'
... in his family's best interests. Breaking News CNN Toggle Search Search 2016 Washington Nation World Our Team CNN.com Biden regrets not running ...

David Brooks: Cruz Running Campaign With 'Dark, Satanic Tones'
David Brooks is all about hauling water for the GOP establishment, but often as not he overreaches, as he does here, making Ted Cruz the embodiment ...

Keep two Macs running at peak performance with this award-winning app
Like all of us, our computers can develop habits over time, not all of them great. Many computers basically become hoarders, getting distracted, ...

Biden On Not Running: ‘I Regret It Every Day’
'It has not been a very illuminating campaign'

'Catfe' restaurant temporarily closes after running out of adoptable cats
'Catfe' restaurant temporarily closes after running out of adoptable cats

Resources last updated: 1/11/2016 3:07:44 AM