Gossamer Forum
Home : Products : DBMan : Customization :

Calling another CGI from within HTML.pl

Quote Reply
Calling another CGI from within HTML.pl
Hi,

I read a lot of the posts below about calling other CGI scripts from within HTML.pl, but I still need help. I saw someone else had this problem, but they didn't seem to find the help they needed, so hopefully I can find it for the both of us.

I stuck this sub routine into db.cgi:
Code:
sub insert_news {
open(FILE, "../news/display.cgi") or die("Couldn't open the file.");
@lines = <FILE>;
close(FILE);
foreach $line (@lines) {
print $line;
}
}

(my news CGI is at ../news/display.cgi)

I also stuck this into HTML.pl:
Code:
|;
&insert_news;
print qq|

Instead of showing the news like as if I was to call it with exec cgi SSI from a .shtml document, it printed out each line of code in display.cgi.

How can I get display.cgi to appear in my HTML output as it would if I was to use a tag like this in a .shtml doc?
Code:
<!--#exec cgi="../news/display.cgi" -->

Do you get what I'm saying? If you could help me, I'd appreciate it greatly.

Thanks.

[This message has been edited by Gliebster (edited October 08, 1999).]
Quote Reply
Re: Calling another CGI from within HTML.pl In reply to
Hello,
You need to store the news in a hash or array I believe.

Try this approch in html.pl

my (%news) = &insert_news;

Now the news is stored in a hash then print
it. Or use a array like.

my (@news) =&insert_news;

|;
print "@news\n";
print qq|

Charlie.....

Wink GOODLUCK Wink



[This message has been edited by mcrickman (edited October 09, 1999).]
Quote Reply
Re: Calling another CGI from within HTML.pl In reply to
Actually, I think the best thing to do would be to include a line like

Code:
<!--#exec cgi="../news/display.cgi" -->

You are correct that your sub insert_news will give you the listing of the file and not the results of running the file.

I'm not real familiar with SSI, but you might try doing a search on the forum for SSI to see what other folks have done.


------------------
JPD





Quote Reply
Re: Calling another CGI from within HTML.pl In reply to
I don't think (from bitter experience) that including an SSI line in html output from cgi will work.

SSI lines are only parsed by the server if they come from a page with a .shtml extension, and html output by cgi isn't being parsed in that way at all.

As I read it - you have an existing perl program that you want to execute from within dbman?

Firstly - this solution (below) may not be practical for all (especially large, complex scripts) but I think it's the only way you can go:

1) Ensure that your whole existing script can be executed as a subroutine. That might mean wrapping up the whole existing script inside a new subroutine (eg "sub action") and making the first line of the script call it as such (eg "&action").

2) INC the existing script into db.cgi in the same way as html.pl is INC'd. You must check that there is no duplication of subroutines or variable between the existing dbman files and your existing script.

3) When you want to run your existing script, call it from within db.cgi, html.pl or whatever as a subroutine (eg "&action").

I know this can work as I have done it for small scripts such as mail lists and banner displays. Effort will be in proportion to the complexity of your existing script.

HTH

Stewart

http://www.circustuff.com/