How to Get output from cgi script

I have 2 systems 1) a linux running the httpd server. on a network with an NT4.0 runing netscape 4.05.
I have a script called counter.cgi (written in perl) that will produce output if either gif file locations or a data string.
This script keeps a count of runs and updates a file called counter.txt. I know the script wotk because the counter gets updated. I need to know how to code the HTML line to display the output of the script, and any other type of setup prior to this to make it work. script is being call from the html file and the counter is updated but I get no Output.
Who is Participating?
jhurstConnect With a Mentor Commented:
Your line <img src=...> in your page expects to receive an image, not text.  You need to modify your cgi to generate an image not text.  

When I needed to do this I browsed the web and found a set of digits as gif files in a public domain area somewhere.  Then when I need to generate the count from my cgi I generate:
  Content-type: image/gif

  then I copy the appropriate image to stdout.

It is a pain in the neck that you can not send text.  
If you can get server side includes, that is an easy way to allow this.  Then your cgi program has only to return a text string which will be included into the document (that text string could be html tags like <IMG src="... if you wanted images).  Otherwise you need to call the cgi program from an <IMG src=""> tag and return image binary data, which I don't know how to do..
Hope this helped a little,
I'm unclear on what you're asking.

Do you want the cgi script to return the entire html sequence for the page, or are you
attempting to just return a small portion of information (like an odometer graphic) ?

If the first, you should be able to just output (from your cgi script)

"Content-type: text/html" followed by a blank line and then whatever html that you wish.

If the latter, you'll need to do as jbirk says and include an <img src="pointer to cgi"> in
your html.  Then, let's assume that you're going to send a bitmap.  You'd have the cgi
write out:

Content-type: image/x-bitmap

#define count_width 10
#define count_height 12
static char count_bits[] = { 120 entries here };

I did this from memory, but it should get you a bit closer.  Assuming that I understood
what you're looking for help with.

Get 10% Off Your First Squarespace Website

Ready to showcase your work, publish content or promote your business online? With Squarespace’s award-winning templates and 24/7 customer service, getting started is simple. Head to and use offer code ‘EXPERTS’ to get 10% off your first purchase.

dpdrAuthor Commented:
This is my Line of code
<IMG SRC=/cgi-bin/counter.cgi>
brouser puts a box like a for an image. if I right click on the image box and then view image the output of the cig script is displayed correctly but not in line on the next request.

From what I think you're asking, I would do the following:

dump all notions of using <img src=...> and simply have your cgi script generate all of the
output needed for the page that you're building.  It's fairly easy to do, and will solve all of
your problems.

Start the output with (be SURE to include the blank line following Content-type!)

Content-type: text/html

and then simply write out whatever fixed html information that you already have

print <<EOF;
    Content-type: text/html

        <title>output from cgi</title>

and then include whatever output, line by line, that your script wants to generate.  Adding in
any appropriate html to format it.  Then, just end the script with


That will generate the entire page for you while avoiding all the problems that you're getting
into with trying to include text via an <img ...>
dpdrAuthor Commented:
I've done some looking and I need to research the setup on the httpd server more.
But also. The people I got the scripts from put it in a line like this
<!--#exec cgi=path to cgi" --> is this a comment or what is exec cgi

Thanks again
this is a server side include, the easiest way to do counters which I mentioned as the first solution.
dpdrAuthor Commented:
Lets close this And I'll take it from there
Did you think that jhurst's answer was the most helpful?  Just making sure since that is who received all the points for this question.
dpdrAuthor Commented:
(can't share points? ) thanks again

I wish they would allow that, so the questioner could split the points up among the people who commented if they thought they where helpful...  oh well.  No bigee.
Customer service will give you points to reward multiple experts for their help if you ask a question there (that's such a pain though).  Just say that you would like to give points to the other experts and they will usually credit your account so you can do so or post a question worth that amount of points for the expert recepient of the points.
Hope everything worked out for you,
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.