Gossamer Forum
Home : General : Perl Programming :

Can I call/invoke another CGI-script from my script

Quote Reply
Can I call/invoke another CGI-script from my script
I want to send a mail to subscribers (not users!) when there has been an update of my DBman database. Since the subscriber list might be getting quite long I think it would be better if this massmailing took place outside DBman.

So the question is can I (and in that case how) invoke another, separate CGI-script from DBman so this scripts does its' task while DBman carry on with the rest.
Quote Reply
Re: Can I call/invoke another CGI-script from my script In reply to
I got one of my programs to to that once. What I did was put this in the program I wanted to send the data from;
open(PIPEOUT, "|filename");

and to have the program read another program you would put this in the script;
open(PIPEIN, "filename|");

I got that information from a book called mastering perl5, by Eric C. Herrmann. In the book it says that the PIPEOUT command is to write to a program, and the description says it is to "send data or command to a program. Also called opening a pipe."
So if you program is going to print something I would use the PIPEIN to read data or a command from another program, on the program you want to send the data to. These methods don't work with .txt or .db files. Only programs. If you don't want to use those try using the require method;
require "path/to/cgilib.pl";
Put that on the program you want to receive the data.

I hope that helped.
Tony
Quote Reply
Re: Can I call/invoke another CGI-script from my script In reply to
Thanks Tony for the tip.

Unfortunately the script won't compile when I use PIPEOUT, so I guess there is a module missing on my server.

However, I have found another way of invoking another script from db.cgi:

Code:
$maillist = 'my_maillist';
$mailer_pgm = $db_script_path . "my_mailer.pl";
system($mailer_pgm, $maillist);

and in my_mailer.pl use $ARGV[1] to catch the name oft the mailinglist.

But with method this db.cgi waits for my_mailer.pl to finish before it continues, which will take longer and longer time the more the mailing list grows. So I need to fork db.cgi somehow....
Quote Reply
Re: Can I call/invoke another CGI-script from my script In reply to
Well, got some help from another source as well, and after brushing up my Unix I got this working exactly as I want it.

Code:
$maillist = 'my_maillist';
$mailer_pgm = $db_script_path . "my_mailer.pl";
if ( fork() == 0 ) {
exec($mailer_pgm, $maillist);
}

Just to let you know Smile
Quote Reply
Re: Can I call/invoke another CGI-script from my script In reply to
 
I'm sorry I didn't get back to you in time. I've been working on three web site this past week and today was the first time I checked the forum in days.
But I'm glad you got it to work. That's quite clever and I think I'll use that in one of my scripts. So thanks to you.

Tony