whiteshark has asked for the wisdom of the Perl Monks concerning the following question:

Greetings Monks.

I have a cgi script written in perl called "chiefdaemon.cgi". This sits in my cgi-bin and runs fine. Within the cgi-bin I also have a perl script called program1.cgi.

The perl engine sits in /usr/bin/perl

chiefdaemon.cgi runs in the background on a timed loop and performs various housekeeping jobs on my site. Depending on the state of the site I want chiefdaemon.cgi to run program1.cgi (in certain circumstances).

I have worked out that I need to be using the exec function, but I cannot get it to work, and none of the on-line tutorials give working examples. In fact most seem to be a cut-and-paste job, as the wording is exactly the same (including the weak pun).

Can anyone tell this lowly initiate what code I should be using? I would be very grateful.

Yours in meditation,

The Whiteshark

Replies are listed 'Best First'.
Re: exec launch
by ikegami (Patriarch) on Aug 25, 2005 at 19:42 UTC

    It what way does it not work? Your post is very light on details, so our assistance will be very general and vague. Perhaps you should show the broken code.

    Do you realize that the exec function never returns when successful? In contrast, the system function returns. Furthermore, the backticks (`...`, qx/.../) operator returns and capture STDOUT. open("|..."), open("...|") and IPC::Run provide means of executing another application in parallel.

    Is program1.cgi really a CGI program? If not, why not rename it to program1.pl. If it is, you need to call it as a CGI program (which means you need to send the POST data to program1's STDIN).

Re: exec launch
by davidrw (Prior) on Aug 25, 2005 at 19:25 UTC
    I think that you want system instead of exec. Note that exec will never return. (see both entries in perlfunc). Or you might want to just fork the other program off... Also check out the Q&A section under QandASection: programs and processes

    also, chiefdaemon.cgi sounds like it might be better suited as a cronjob (or set of cronjobs) .. do you have crontab access? And also, why is a cgi program doing cron'd ("timed loop") stuff (as opposed to a standalone script, perhaps w/shared code)?