Apache uses CGI to call the EXE program

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.