CGI with C++

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.

Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Can you give a bit more info. Its like guessing at this point.
mahaAuthor Commented:
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.

Try checking that directory is dos - CGI not WIN-CGI.
Introduction to R

R is considered the predominant language for data scientist and statisticians. Learn how to use R for your own data science projects.

More info please:

Operating system?
C compiler?
C++ compiler?
Web Server?
Why is it not possible to debug the program?
mahaAuthor Commented:
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.
Is there anything in the web server log files that might point to some problem with the executable when the problem occurs?
Send me the code.

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.

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.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
mahaAuthor Commented:
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("Testing C++ CGI \n");

    return 0;

Even this simple program behaves inconsistently.

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


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;

My code works.
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.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Scripting Languages

From novice to tech pro — start learning today.