Page 1 of 2

problems executing C code

PostPosted: 21. July 2009 11:18
by rohan
Hello everyone,

I want to use Xampp for executing C code.

My c file name is abc.c
So, what I did, as i do in linux (fedora 9), I compiled the code

gcc -o abc.cgi abc.c

now i put this .cgi file in cgi-bin folder and things work fine in fedora.

But when I put abc.cgi in cgi-bin folder in xampp it doesnt work. In both cases i've my html file in html folder (in fedora) and htpdocs in xampp.

here is the following error i get

Server error!

The server encountered an internal error and was unable to complete your request. Either the server is overloaded or there was an error in a CGI script.

If you think this is a server error, please contact the webmaster.

Error 500
localhost
07/21/09 12:17:14
Apache/2.2.11 (Win32) DAV/2 mod_ssl/2.2.11 OpenSSL/0.9.8i PHP/5.2.9


thank you in advance

Re: xampp for executing cgi application

PostPosted: 21. July 2009 12:16
by Wiedmann
what I did, as i do in linux (fedora 9), I compiled the code
...
Apache/2.2.11 (Win32)

How want you run a binary, compiled for Linux, on Windows?

Re: problems executing C code

PostPosted: 21. July 2009 13:18
by rohan
ok.. i knw its wrong..

but any solution.. for running C code with CGI script.. in APACHE..

Re: problems executing C code

PostPosted: 21. July 2009 13:21
by Wiedmann
but any solution.. for running C code

Compile it.

Re: problems executing C code

PostPosted: 21. July 2009 13:22
by rohan
compile where?.. on linux?..

Re: problems executing C code

PostPosted: 21. July 2009 13:48
by Wiedmann
compile where?.. on linux?..

If the binary should run on Linux, yes. If it should run on Windows, on Windows.

Re: problems executing C code

PostPosted: 21. July 2009 14:24
by rohan
So, what is the wrong in following steps

here is the code
abc.c
#include<stdio.h>
main()
{
printf("Content-type: text/html\n\n");
printf("hey");
printf("</html>");
}


steps..
1. compile the code in fedora using gcc
gcc -o abc.cgi abc.c

2. put the abc.cgi in cgi-bin of xampp on windows

The code works fine on fedora..but gives the error as mentioned earlier on windows.

When i checked the logs of apache

access file
"GET /cgi-bin/abc.cgi HTTP/1.1" 500 1122

Re: problems executing C code

PostPosted: 21. July 2009 14:52
by Wiedmann
So, what is the wrong in following steps

As I told you above:
- You can't use a Linux binary on Windows (that's the reason there is a XAMPP for Windows and a XAMPP for Linux).
- If you want use this C source on WIndows, you must compile it on Windows (not on Linux).

Re: problems executing C code

PostPosted: 21. July 2009 16:27
by rohan
Thank you for replying patiently.

I installed Turbo C on windows and compiled the code.

Still the error is the same.

After compiling the code on Turbo C. I put the object file in the cgi-bin folder. Still the problem remains the same.

I'm a beginner so kindly help me with this.
Thank you lot.

Re: problems executing C code

PostPosted: 21. July 2009 16:31
by Wiedmann
I put the object file in the cgi-bin folder.

You mean the EXE file? Can you execute it in the shell?

Re: problems executing C code

PostPosted: 21. July 2009 16:40
by rohan
I tried to put two files one by one.
1. object file (file with extension .obj)
2. executable file (file with extension .exe)

Both gives the fail results.

Re: problems executing C code

PostPosted: 21. July 2009 16:45
by Wiedmann
You can only run *.exe (or *.com) files.

Well, if you can't start this *.exe file in the shell, you should ask the Turbo C support how to use their compiler (don't know anything about Turbo C).

Re: problems executing C code

PostPosted: 21. July 2009 16:55
by rohan
I can run the code in shell

Following is the output i get after running in the shell

Content-type: text/html

<html><body>hey</body></html>



And now when i put .exe file in cgi-bin folder. It ask the 'abc.exe' to store on the computer and is not displaying the result. There is no error but its not displaying and giving back the .exe file.

Re: problems executing C code

PostPosted: 21. July 2009 17:00
by Wiedmann
And now when i put .exe file in cgi-bin folder

That's the folder "C:\xampp\cgi-bin\"?

It ask the 'abc.exe' to store on the computer and is not displaying the result

So you don't have the error 500 anymore?

Re: problems executing C code

PostPosted: 21. July 2009 17:02
by rohan
yes
for both the questions.