Solved

CGI with C++

Posted on 1998-02-04
11
447 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
How Do You Stack Up Against Your Peers?

With today’s modern enterprise so dependent on digital infrastructures, the impact of major incidents has increased dramatically. Grab the report now to gain insight into how your organization ranks against your peers and learn best-in-class strategies to resolve incidents.

 
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
 
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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

Preface In the first article: A Better Website Login System (http://www.experts-exchange.com/A_2902.html) I introduced the EE Collaborative Login System and its intended purpose. In this article I will discuss some of the design consideratio…
Active Directory replication delay is the cause to many problems.  Here is a super easy script to force Active Directory replication to all sites with by using an elevated PowerShell command prompt, and a tool to verify your changes.
The viewer will learn how to count occurrences of each item in an array.
Video by: Mark
This lesson goes over how to construct ordered and unordered lists and how to create hyperlinks.

730 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