Solved

CGI with C++

Posted on 1998-02-04
11
443 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
Comment Utility
Can you give a bit more info. Its like guessing at this point.
0
 

Author Comment

by:maha
Comment Utility
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
Comment Utility
Try checking that directory is dos - CGI not WIN-CGI.
0
 
LVL 32

Expert Comment

by:jhance
Comment Utility
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
Comment Utility
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
What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

 
LVL 32

Expert Comment

by:jhance
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

Join & Write a Comment

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…
This article is meant to give a basic understanding of how to use R Sweave as a way to merge LaTeX and R code seamlessly into one presentable document.
Viewers will learn one way to get user input in Java. Introduce the Scanner object: Declare the variable that stores the user input: An example prompting the user for input: Methods you need to invoke in order to properly get  user input:
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

744 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

17 Experts available now in Live!

Get 1:1 Help Now