在apache上运行.exe文件?

时间:2014-08-15 10:40:13

标签: apache cgi exe

我正在尝试通过html表单运行cgi可执行文件,如下代码所示:

 <html>

 <head>
<title>CGI Form</title>
<meta http-equiv="content-type" content="text/html;charset=utf-8" />
</head>

<body>
<form action="C:\WWW\cgi-bin\y.exe" method="get">
    <input type="text" name="string1" />
    <input type="text" name="string2" />
    <input type="text" name="string3" />
    <input type="submit" name="submit" value="Submit" />
</form>
</body>

</html>

这里是编译为y.exe的cgi代码,保存在action:

中指定的路径中
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

int main(void)
{
char *buffer, string1[100], string2[100], string3[100], merged[300]; 

buffer = getenv("QUERY_STRING"); 

if(buffer == NULL) 
{
    printf("<p>Error: No data</p>");
}
else
{
    if(sscanf(buffer, "string1=%s&string2=%s&string3=%s", string1, string2, string3) !=      3) 
    {
        printf("Data missing!");
    }
    else
    {   
        strcpy(merged, string1); 
        strcat(merged, string2); 
        strcat(merged, string3); 

        printf("Content-Type: text/html\n\n");
        printf("<html>\n"
               "<head>\n"
                   "<title>CGI Form Merge Strings</title>\n"
               "</head>\n"
               "<body>\n"
                   "Merged string is: %s\n"
               "</body>\n"
               "</html>\n", merged);  
    }
}

return 0;

}

我尝试用以下方法重新配置httpd.conf文件:

AddHandler cgi-script .exe
ScriptAlias /cgi-bin/ "C:/WWW/cgi-bin/"

<Directory "C:/WWW/cgi-bin">
    AllowOverride All
    Options +ExecCGI
    Options FollowSymLinks 
    Require all granted
    AddHandler cgi-script .cgi
    AddHandler cgi-script .exe
</Directory>

然而,这并不能解决问题。

1 个答案:

答案 0 :(得分:1)

action="C:\WWW\cgi-bin\y.exe" 

您需要在此处提供HTTP URI。它可能是:

action="/cgi-bin/y.exe"