Solved

CGI with C++

Posted on 1998-02-04
11
444 Views
Last Modified: 2013-12-25
Hi there,

    I am facing a strange problem. I have written a CGI in C which generates dymanic html based on the user.If I compile it with C compiler and execute, it works great. As I need to use some C++ classes, I planned to make it C++ program. So before actually modifying the program, I compiled the same program with C++ compiler( it is compatible with C compiler I used.) But the behaviour of C++ exe is not consistent. Sometime it works fine, sometime it gives "Document Not Found" error. It is not possible to debug the program.
Can somebody help me out??

Note: I have lot of printf statements in C program, I tried changing it to cout. Still it did not work.

 
0
Comment
Question by:maha
  • 3
  • 3
  • 2
  • +2
11 Comments
 
LVL 3

Expert Comment

by:vmpn
ID: 1831918
Can you give a bit more info. Its like guessing at this point.
0
 

Author Comment

by:maha
ID: 1831919
What kind of info do U need?? By the way, C++ exe works great on other m/c's cgi-bin directory. I am using cern web sever v. 3.0, so is the other m/c. Is it something to do with configuration?  If so what it can be? I checked both the configuration files (httpd.conf) They are similar.

0
 
LVL 3

Expert Comment

by:vmpn
ID: 1831920
Try checking that directory is dos - CGI not WIN-CGI.
0
 
LVL 32

Expert Comment

by:jhance
ID: 1831921
More info please:

Operating system?
C compiler?
C++ compiler?
Web Server?
Why is it not possible to debug the program?
0
 

Author Comment

by:maha
ID: 1831922
Operating System : SunOS 5.5.1
C Compiler : v.2.0.1
C++ compiler :v.3.0.2e
Web Sever : cern 3.0

For debugging, the only thing, I tried,was running the CGI from command line and redirecting the output to file and checking it. Both EXEs give same desirable result.
0
3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

 
LVL 32

Expert Comment

by:jhance
ID: 1831923
Is there anything in the web server log files that might point to some problem with the executable when the problem occurs?
0
 
LVL 1

Expert Comment

by:jasonc
ID: 1831924
Send me the code.  bitbucket@null.net

Also, which document is your browser looking for when things don't work?  If you're receiving a 404 error, the URL in your browser CANNOT be the same as when it did work.

0
 
LVL 8

Accepted Solution

by:
jhurst earned 20 total points
ID: 1831925
try closing the file that your are generating the output to.  Even if it is stdout.  It seems that the flush will be required to cause the output to actually get passed to the system.
0
 

Author Comment

by:maha
ID: 1831926
Hi there,
I tried closing the stdout. It did not work.
I am not getting 404 error. I get a dialog box saying "Document contains not data". Actually I did try writing a simple test routine to check whether it works with simple code. Following is my test code,

#include <stdio.h>

int main(int, char**)
{
    printf("Content-type:text/html\n\n");
    printf("<html>\n");
    printf("<body>\n");
    printf("Testing C++ CGI \n");
    printf("</body>\n");
    printf("</html\n");

    return 0;
}

Even this simple program behaves inconsistently.

I couldn't understand jhance's comments. Can U elaborate?

Thanx,
Maha


0
 
LVL 8

Expert Comment

by:jhurst
ID: 1831927
It does look OK, however, I do not see the close().  I looked at my code and I am note sure why but I always do:
  FILE *out=stdout;
  fprintf(out,xxxx
  fclose(out);

My code works.
0
 
LVL 32

Expert Comment

by:jhance
ID: 1831928
You are probably doing the fclose() in order to ensure that no characters are hanging around in the output buffer and not sent to the web server.  It shouldn't be a problem as the C run-time library should call fflush() on stdout before it terminates and closes the file.  Doing it manually shouldn't hurt.
0

Featured Post

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I will show you how to create a ASP.NET Captcha control without using any HTTP HANDELRS or what so ever. you can easily plug it into your web pages. For Example a = 2 + 3 (where 2 and 3 are 2 random numbers) Session("Answer") = 5 then we…
What is Node.js? Node.js is a server side scripting language much like PHP or ASP but is used to implement the complete package of HTTP webserver and application framework. The difference is that Node.js’s execution engine is asynchronous and event…
Viewers will learn about arithmetic and Boolean expressions in Java and the logical operators used to create Boolean expressions. We will cover the symbols used for arithmetic expressions and define each logical operator and how to use them in Boole…
The viewer will learn how to count occurrences of each item in an array.

932 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now