In Windows, a simple CGI program is written in C to generate an executable file of the EXE type. The Code is as follows:
1 #include<stdio.h>2 int main()3 {4 printf("Content-Type:text/html\n\n"); 5 printf("Hello,world!\n");6 return 0;7 }
How does one make Apache load the generated EXE file? You only need to perform the following two steps:
1. Configure the directory where the CGI program is located
2. Enable Apache to identify the EXE file
The configuration files corresponding to Apache are:
A:
<Ifmodule alias_module> added the following code block:
ScriptAlias/cgi-bin/"E:/C /"
The directory where the CGI program (the generated EXE file) is located in red
Note: You need to modify the following two parts:
1 <Directory "E:/c">2 AllowOverride None3 Options None4 Order allow,deny5 Allow from all6 </Directory>
B:
<Ifmodule mime_module> modify or add the following two lines to the code block:
Addtype text/html. exe
Addhandler CGI-script. EXE. cgi
Assume that the generated EXE file is test.exe.
Copy test.exe to the E: \ c directory and restart Apache.
Run http: // localhost/cgi-bin/test.exe in the browser. If you see hello, world! The configuration is successful.
Extension:
Use the following example to accept get and post data in C:
1 # include <stdio. h> 2 # include <stdlib. h> 3 # include <string. h> 4 int main () 5 {6 char * data; 7 long M, N; 8 9 printf ("Content-Type: text/html \ n "); 10 printf ("<title> HTML generated by C language </title>"); 11 12 Data = getenv ("QUERY_STRING"); 13 if (null = data) 14 printf ("<p> error. </P> "); 15 else if (sscanf (data," m = % LD & n = % lD ", & M, & N )! = 2) 16 printf ("<p> Please input number. </P> "); 17 else18 printf (" <p> M: % LD; N: % lD. </P> ", m, n); 19 Return 0; 20}
Apache uses CGI to call the EXE program