Jump to content

Problem combining c++ and .cgi

- - - - -

This topic has been archived. This means that you cannot reply to this topic.
2 replies to this topic

#1
Guest_yuide_*

Guest_yuide_*
  • Guests
I am attempting to write a c++ program and run it on a web server using .cgi. I've tried some examples found by googling and failed so i guess there is some other error rather than error in the actual code.
However, this is what the program i try with look like:

int main(int argc, char *argv[])

{std::cout<<"Content-type: text/html\n\n";

std::cout<<"along with some other text\n";

return(0);}

When I run this on the server I get the message
"Internal Server Error
The server encountered an internal error or misconfiguration and was unable to complete your request.", which is the same error I have received when i've, for example, tried to run a perl script with some error in it.
I have, by the way, managed to run perl scripts with .cgi in the same way i am trying to execute c++ programs.

As I said, there is possibly some other error than broken code. This is how I do when I upload my program (of which i'm unsure of how it should be done)
I'm using Linux.
prompt comment
g++ test.cc -o test.out
mv test.out test.cgi
./test.cgi test.cgi works fine here
gftp& ftp program
- -
[in gftp:
transferring test.cgi to /test.cgi/
i have the ftp program set to ascii mode and the correct permissions]
then i open /test.cgi/ in firefox and the error appers.

This is my first post so i can't easily post links. However /test.cgi is located at www DOT yuide DOT se /test.cgi

Any ideas what might be the error?

#2
v0id

v0id

    Retired

  • Members
  • PipPipPipPipPipPipPipPipPip
  • 2,936 posts
Think about it, C++ is a compiled language, it isn't possible to do what you try to do. If you make a normal C++ language and compile it using, f.ex. G++, then it will be outputted in a output-file, executable-file, or some other file-type or format.

Think about an application, f.ex. the one before, it compiles into (fiction):
()d9s7bA(B)68329876876Ø*saø'3w2_strange signs_498329xh32s97426348234
Then if you open it, using your browser - it would be that the browser reads. To do what you want to do, you have to use some kind of framework for CGI + C++, it could be used directly on the server or something you use, before uploading, that will be transformed into normal HTML-tags.

I've never been working with CGI and C++, because I see no idea in using it, when we have PHP - or any other weblanguage, which is built to do it, which C++ isn't. I've only heard of one framework, and I've no experience with it, so I can't say if it's good - or not.

It's ppC++, and can be found here: ppC++ Home Page

#3
Guest_yuide_*

Guest_yuide_*
  • Guests
Thanks for your answer.
It's probably true that C++ is not optimal for these purposes, but I already have some programs I want to upload.
ppC++ seems like a good solution to the problem.