Gossamer Forum
Home : Products : DBMan : Customization :

Run cgi script within html.pl

(Page 1 of 2)
> >
Quote Reply
Run cgi script within html.pl
I know that you can't use SSI within the html.pl - what I am trying to do is run a "Random Quote" script within the html.pl.

I tried to use the information from the ad banner rotation script "Web Adverts" but it isn't working. Instead of displaying the "Quote" it displays the entire script.

Any ideas?

TIA -

Donm
Quote Reply
Re: [donm] Run cgi script within html.pl In reply to
I use SSI all the time within my scripts for both for side menus and footers. But I use the user friendly version and have my SSI calls within a format.pl file.

How are you having to call your random quote script? Is it with a virtual include?

Have you check the various thread in the FAQ under "SSI" and "Files"

There a thread called "SSI Include Replacement" which might also help to find a solution.

Unoffical DBMan FAQ

http://creativecomputingweb.com/dbman/index.shtml/
Quote Reply
Re: [LoisC] Run cgi script within html.pl In reply to
I tried the "SSI Include Replacement" from the DBMan FAQ and still no luck - I get an "Internal Server Error".

Here is the code I am using:

I put this in db.cgi

##########################
## SSI Include Replacement ##
###########################

sub include_quotes {
# --------------------------------------------------------
# This is text to include. Use like an SSI.

my $file = ''/home/WWW10/cocoahighalumni.com/cgi-bin/tips/tip.pl'';
open (FILE, ''<$file'') or die ''Can't open $file ($!)'';
print ;
close FILE;
}


And this goes in html.pl where I want the quote to print out:

|;&include (''/home/WWW10/cocoahighalumni.com/cgi-bin/tips/tip.pl'');print qq|



Any ideas on what I may be doing wrong?



Donm
Quote Reply
Re: [donm] Run cgi script within html.pl In reply to
Since you named the new sub: sub include_quotes

Then when you call it you would need to use:

|;
&include_quotes("/home/WWW10/cocoahighalumni.com/cgi-bin/tips/tip.pl");
print qq|

Unoffical DBMan FAQ

http://creativecomputingweb.com/dbman/index.shtml/
Quote Reply
Re: [LoisC] Run cgi script within html.pl In reply to
ok now I don't receive the error anymore - but it appears that the script isn't working either.

It is just blank where the quotes should appear.

Donm
Quote Reply
Re: [donm] Run cgi script within html.pl In reply to
I think perhaps you changed too much within the sub try it like this .. it was setup to be used to pull in various files with just one subroutine. When you call the sub is the only place you need to define the path and specific file.

sub include {
# --------------------------------------------------------
# This is text to include. Use like an SSI.

my $file = shift;
open (FILE, "<$file") or die "Can't open $file ($!)";
print <FILE>;
close FILE;
}

Then add this line wherever you want the file included:

|;
&include ("/home/WWW10/cocoahighalumni.com/cgi-bin/tips/tip.pl");
print qq|

When i use this to pull in .txt files I just add the name of the .txt file without the path .. due to it being stored in the same directory as the DBMan files.

Unoffical DBMan FAQ

http://creativecomputingweb.com/dbman/index.shtml/
Quote Reply
Re: [LoisC] Run cgi script within html.pl In reply to
When I use the code that you provided it prints out the entire script like this:

#!/usr/local/bin/perl ####################################################### # Tip of the Moment V2.2 # # This program is distributed as freeware. We are not # responsible for any damages that the program causes # to your system. It may be used and modified free of # charge, as long as the copyright notice # in the program that give me credit remain intact. # If you find any bugs in this program. It would be thankful # if you can report it to us at cgifactory@cgi-factory.com. # However, that email address above is only for bugs reporting. # We will not respond to the messages that are sent to that # address. If you have any trouble installing this program. # Please feel free to post a message on our CGI Support Forum. # Selling this script is absolutely forbidden and illegal. ################################################################## # # COPYRIGHT NOTICE: # # Copyright 1999-2000 CGI-Factory.com TM # A subsidiary of SiliconSoup.com LLC # # # Web site: http://www.cgi-factory.com # E-Mail: cgifactory@cgi-factory.com # Released Date: April 1, 2000 # # Tip of the Moment V2.2 is protected by the copyright # laws and international copyright treaties, as well as other # intellectual property laws and treaties. ################################################################### require "cfg.pl"; &tip; sub tip{ open (DAT,"<$messages_location/count.txt") || &error1("unable to open counts.txt"); if ($flock eq "y") { flock DAT, 2; } $dat = ; close (DAT); $dat++; srand (); $rand_num = rand($dat); $rand_num = int($rand_num); if ($rand_num=~ tr/;<>*|`&$!#()[]{}:'"//) { print "Content-type: text/html\n\n"; print "Security Alert! Action canceled.
\n"; print "Please don't use weird symbols\n"; exit; } open (DATA,"<$messages_location/$rand_num.txt") || &error; if ($flock eq "y") { flock data, 2; } @data = ; $data = ; close (DATA); print "Content-type: text/html\n\n"; print "$title\n"; if ($showdate==1) { print ""; &date; print ""; } print "

\n"; foreach $data (@data) { print "$data\n"; } print ""; exit; } sub error1{ $errors = $_[0] ; print "Content-type: text/html\n\n"; print "An error occured,
\n"; print "the error is $errors
\n"; print "reason: $!\n"; exit; } sub error{ print "Content-type: text/html\n\n"; print "$title\n"; if ($showdate==1) { print ""; &date; print ""; } print "

\n"; print "Nothing at this moment.\n"; print ""; if ($email=~ tr/;<>*|`&$!#()[]{}:'"//) { print "Content-type: text/html\n\n"; print "Security Alert! Action canceled.
\n"; print "Please don't use weird symbols\n"; exit; } open(MAIL,"|$mail_prog -t"); print MAIL "To: $email\n"; print MAIL "From: $email\n"; print MAIL "Subject: File NO. $rand_num is missing \n\n"; print MAIL "For some reasons, the file $rand_num.txt is missing.\n"; print MAIL "You may want to check your message database. :)\n"; close (MAIL); exit; } sub date { @months = ('January','February','March','April','May','June','July','August','September','October','November','December'); @days = ('Sunday','Monday','Tuesday','Wednesday','Thursday','Friday','Saturday'); ($sec,$min,$hour,$mday,$mon,$year,$wday) = (localtime)[0,1,2,3,4,5,6]; $sec = sprintf("%.02d",$sec); $min = sprintf("%.02d",$min); $hour = sprintf("%.02d",$hour); $mday = sprintf("%.02d",$mday); $year += 1900; $date = "$days[$wday], $months[$mon] $mday, $year"; $date = "$days[$wday], $months[$mon] $mday, $year"; print "$date"; }

Donm
Quote Reply
Re: [donm] Run cgi script within html.pl In reply to
I looked at the readme file for the script you are using and it doesn't show that you can call it using virtual include which may be the problem. That is why I asked earlier how you were calling the script.

Perhaps your best bet at this point would be to search the forum for threads relating to "exec cgi" and see if you can find a solution. I'm sure others have asked similiar questions and had the same type calls being needed.

Or perhaps someone else will come along to help you find a solution.

Unoffical DBMan FAQ

http://creativecomputingweb.com/dbman/index.shtml/
Quote Reply
Re: [LoisC] Run cgi script within html.pl In reply to
When I make the call from a static page I use the following:

!--#exec cgi="/cgi-bin/tips/tip.pl" --

I am using the following and it looks like its working - but instead of printing out the random quote - it is printing out the entire code from the script.



Here is what I am using:

In db.cgi I add -

sub include_file {
#------------------------------------------------------------------------------
# This is the sub routine for including files
open(FILE, "/home/WWW10/cocoahighalumni.com/cgi-bin/tips/tip.pl") or die("Couldn't open the file.");
@lines = <FILE>;
close(FILE);
foreach $line (@lines) {
print $line;
}
}

and in html.pl I add

|;
&include_file;
print qq|

But as I said instead of printing out one of the random quotes - it spits out the entire code of the tip.pl

I have read a few of the posts from others having the same problem - but the posts never say whether a solution was ever achieved?

Anyone ever ran into this and have a solution? Your help would be greatly appreciated.

donm
Quote Reply
Re: [donm] Run cgi script within html.pl In reply to
You will probably want something like ths:

Code:
my $output = qx|/path/to/script.pl|;

That should do what you desire if I've understood. I think Lois's idea just reads the file content rather than compiles it but I didn't read much of the thread above to be honest Wink
Quote Reply
Re: [Paul] Run cgi script within html.pl In reply to
Paul -

Yes, it seems that is what the example that Lois has shown does - reads the file. BTW Lois, please forgive me for not thanking you for your help - it was much appreciated.

Paul I am not sure exactly what example you are showing does? Does it need to be added in addition to the code that Lois has provided?

Thanks for your help!

donm
Quote Reply
Re: [donm] Run cgi script within html.pl In reply to
No, that's all you need. It will execute your script and assign the output to $output for you then to print...eg....

test.pl

Code:
#!/usr/bin/perl

use strict;
main();

sub main {

my $rand = ['I am a random quote', 'I am another', 'So am I'];
return $rand->[rand @$rand];
}

DBMAN:

Code:
my $output = qx/test.pl/;

$output should now contain a random quote.
Post deleted by donm In reply to
Quote Reply
Re: [Paul] Run cgi script within html.pl In reply to
Paul -

I cut and pasted your $output example into my html.pl - even made a separate test.pl like yours to test.... but nothing prints out at all?

donm
Quote Reply
Re: [donm] Run cgi script within html.pl In reply to
I guess that's because in Paul's example the code is contained in a subroutine, but you just call the script by its name, not telling it which subroutine to execute.

What happens if you delete the "sub main { ..............}" part around the code?

BTW, you could also try a simple:

do("test.pl");

In which case you should have the print statement inside test.pl
kellner
Quote Reply
Re: [kellner] Run cgi script within html.pl In reply to
Still nothing when the "sub" part is removed.... when I try to run just "test.pl" I get "Internal Server Error".

donm
Quote Reply
Re: [donm] Run cgi script within html.pl In reply to
actually, I was wrong with what I wrote about Paul's code - I overlooked the line "main()" in the beginning. So Paul's code should actually work.



The server error is no surprise: the script "test.pl" does not print a http header, so when called on its own through a web server, then you get the error.

What if test.pl only contains the line

print "test";

Does that work?
kellner
Quote Reply
Re: [kellner] Run cgi script within html.pl In reply to
Still nothing... test.pl only contains:

print "test";

donm
Quote Reply
Re: [donm] Run cgi script within html.pl In reply to
ok, then please post:

- the actual content of test.pl

- the block of code from which you call it



maybe a simple typo, who knows ...
kellner
Quote Reply
Re: [kellner] Run cgi script within html.pl In reply to
Test.pl contains:

#!/usr/bin/perl

print "test";



and this is the line that makes the call which is in html.pl :

my $output = qx|/home/WWW10/cocoahighalumni.com/cgi-bin/alumni/test.pl|;



donm
Quote Reply
Re: [donm] Run cgi script within html.pl In reply to
not just the line which calls it - but also what you then do with it, after calling it.
kellner
Quote Reply
Re: [kellner] Run cgi script within html.pl In reply to
<table cellspacing="2" cellpadding="2" border="0">
<tr>
<td>|;

my $output = qx|/home/WWW10/cocoahighalumni.com/cgi-bin/alumni/test.pl|;

print qq|</td>
</tr>
<tr>

</table>
Quote Reply
Re: [donm] Run cgi script within html.pl In reply to
Ok. I don't know how to use the "qx"-syntax, and maybe Paul posts a better idea later.

Here's what I usually do in such cases, and it works:

test.pl

my $var = "just an example";

print "$var\n";



main script:

<table cellspacing="2" cellpadding="2" border="0">
<tr>
<td>|;

do("test.pl");

print qq|</td>
</tr>
<tr>

</table>
kellner
Quote Reply
Re: [kellner] Run cgi script within html.pl In reply to
ok, all that does is print out what is in "my $var". I need something that will actually execute another cgi script from within html.pl

donm
Quote Reply
Re: [donm] Run cgi script within html.pl In reply to
well, then replace the content of test.pl which whatever code it is you want to execute, make sure to add a print-statement at the end to print the result, and that's it.
kellner
> >