Solved

CGI with C++

Posted on 1998-02-04
11
445 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
DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

 
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

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

Suggested Solutions

Title # Comments Views Activity
Wallpaper not updating when file is swapped out 6 56
Active DirectoryScript to change the Pager Field 1 64
Questions about this React unit test 4 63
Powershell File Sort 8 31
Browsers only know CSS so your awesome SASS code needs to be translated into normal CSS. Here I'll try to explain what you should aim for in order to take full advantage of SASS.
Have you tried to learn about Unicode, UTF-8, and multibyte text encoding and all the articles are just too "academic" or too technical? This article aims to make the whole topic easy for just about anyone to understand.
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 …
In this fourth video of the Xpdf series, we discuss and demonstrate the PDFinfo utility, which retrieves the contents of a PDF's Info Dictionary, as well as some other information, including the page count. We show how to isolate the page count in a…

777 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