problems executing C code

Problems with the Windows version of XAMPP, questions, comments, and anything related.

problems executing C code

Postby rohan » 21. July 2009 11:18

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
rohan
 
Posts: 10
Joined: 21. July 2009 11:12

Re: xampp for executing cgi application

Postby Wiedmann » 21. July 2009 12:16

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?
Wiedmann
AF Moderator
 
Posts: 17102
Joined: 01. February 2004 12:38
Location: Stuttgart / Germany

Re: problems executing C code

Postby rohan » 21. July 2009 13:18

ok.. i knw its wrong..

but any solution.. for running C code with CGI script.. in APACHE..
rohan
 
Posts: 10
Joined: 21. July 2009 11:12

Re: problems executing C code

Postby Wiedmann » 21. July 2009 13:21

but any solution.. for running C code

Compile it.
Wiedmann
AF Moderator
 
Posts: 17102
Joined: 01. February 2004 12:38
Location: Stuttgart / Germany

Re: problems executing C code

Postby rohan » 21. July 2009 13:22

compile where?.. on linux?..
rohan
 
Posts: 10
Joined: 21. July 2009 11:12

Re: problems executing C code

Postby Wiedmann » 21. July 2009 13:48

compile where?.. on linux?..

If the binary should run on Linux, yes. If it should run on Windows, on Windows.
Wiedmann
AF Moderator
 
Posts: 17102
Joined: 01. February 2004 12:38
Location: Stuttgart / Germany

Re: problems executing C code

Postby rohan » 21. July 2009 14:24

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
rohan
 
Posts: 10
Joined: 21. July 2009 11:12

Re: problems executing C code

Postby Wiedmann » 21. July 2009 14:52

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).
Wiedmann
AF Moderator
 
Posts: 17102
Joined: 01. February 2004 12:38
Location: Stuttgart / Germany

Re: problems executing C code

Postby rohan » 21. July 2009 16:27

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.
rohan
 
Posts: 10
Joined: 21. July 2009 11:12

Re: problems executing C code

Postby Wiedmann » 21. July 2009 16:31

I put the object file in the cgi-bin folder.

You mean the EXE file? Can you execute it in the shell?
Wiedmann
AF Moderator
 
Posts: 17102
Joined: 01. February 2004 12:38
Location: Stuttgart / Germany

Re: problems executing C code

Postby rohan » 21. July 2009 16:40

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.
rohan
 
Posts: 10
Joined: 21. July 2009 11:12

Re: problems executing C code

Postby Wiedmann » 21. July 2009 16:45

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).
Wiedmann
AF Moderator
 
Posts: 17102
Joined: 01. February 2004 12:38
Location: Stuttgart / Germany

Re: problems executing C code

Postby rohan » 21. July 2009 16:55

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.
rohan
 
Posts: 10
Joined: 21. July 2009 11:12

Re: problems executing C code

Postby Wiedmann » 21. July 2009 17:00

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?
Wiedmann
AF Moderator
 
Posts: 17102
Joined: 01. February 2004 12:38
Location: Stuttgart / Germany

Re: problems executing C code

Postby rohan » 21. July 2009 17:02

yes
for both the questions.
rohan
 
Posts: 10
Joined: 21. July 2009 11:12

Next

Return to XAMPP for Windows

Who is online

Users browsing this forum: No registered users and 118 guests