是否有可能运行一个批处理文件与Windows下的Apache的一个CGI? [英] Is it possible to run a batch file as a cgi in apache under windows?
问题描述
这听起来非常简单的事,但我不能使它工作。我有它使用awk和perl的工作,但CMD.EXE没有设计成一个CGI程序所以无论我做什么,我要么得到浏览器下载文件,内部服务器错误,还是我得到当前的路径目录作为第一行
您必须把#!在CGI的第一行,或者你会得到一个内部服务器错误,但我结束了
C:\\ Program Files文件(x86)的\\ Apache软件基金会\\的Apache2.2 \\ cgi-bin目录>#!C:\\ WINDOWS \\ SYSTEM32 \\ CMD.EXE / C
内容类型:text / html的< HTML>< BODY>
< pre>你的环境变量是:
< / pre>< / BODY>< / HTML>
我试着/ C,没有,任何数量的排列,它总是显示当前的工作目录首先任何东西之前,所以我不能打印出内容类型作为标题。
有人曾经得到这个工作?我看到很多在谷歌结果表明我的猜测,但没有实际工作的例子。
-
首先检查阿帕奇mine.types,注释掉这一行。
#应用程序/ x-msdownload EXE COM DLL蝙蝠MSI
到
应用程序/ x-msdownload EXE COM DLL蝙蝠MSI
这行的意思是:阿帕奇治疗EXE,DLL,COM,BAT,MSI文件下载文件,而不是excuting它。
所以,如果ü要运行CGI bat文件,ü需要其注释掉。(我猜ü已经做到这一点,以防万一有人新这么想的就知道了。#AddHandler CGI脚本的CGI蝙蝠.EXT
我试过,如果u留注释掉使用Apache的Zend 2.2服务器将不会influence.I'm这上面一行。所以才息事宁人。
-
写乌尔bat文件
#!C:\\ WINDOWS \\ SYSTEM32 \\ CMD.EXE / C
这种壳状评论不工作,在第一BAT / CMD文件,你需要写:
关闭@echo
回声内容类型:文本/纯
回声。
这条线之上意味着输出新行,如果u没有这样做,你也会得到脚本头premature结束:xxx.bat500 HTTP错误
呼应^< HTML ^>
^是逃避CMD字符。
回声....
为什么乌尔蝙蝠不工作的原因是因为,美都不会粘在HTTP protocal。
-
把UR BAT / CMD / EXE文件到cgi-bin目录。
现在,检查出来。
-
提醒:读取HTTP protocal
。 -
其他问题:
如果u在乌尔CGI bat文件调用其它EXE如 curl.exe ,它会无法按预期工作,我不知道为什么,任何信息都是感谢。
- 是指: http://www.jlk.net/apache/debugging_cgi.shtml
This sounds incredibly simple to do, but I can't make it work. I have it working with awk and perl, but cmd.exe wasn't designed to be a cgi program so no matter what I do, I either get the browser downloading the file, internal server error, or I get the path of the current directory as the first line.
You HAVE to put a #! in the first line of a cgi, or you get an internal server error, but I end up with
C:\Program Files (x86)\Apache Software Foundation\Apache2.2\cgi-bin>#!c:\windows\system32\cmd.exe /c
Content-Type: text/html
<HTML><BODY>
<PRE>Your environment variables are:
</PRE></BODY></HTML>
I've tried with /c, without, any number of permutations, it always prints the current working directory first before anything, so I can't print out the content type as a header.
Anybody ever get this working? I see lots of speculation in the results google shows me, but no actual working examples.
first check apache mine.types, comment out this line .
#application/x-msdownload exe dll com bat msi
to
application/x-msdownload exe dll com bat msi
this line means : apache treat exe,dll,com,bat,msi file as download file instead of excuting it. so if u want to run bat file in cgi , u need to comment it out.(I guess u already do that,just in case somebody new dosen't know.
#AddHandler cgi-script .cgi .bat .ext
as i tried, if u left this above line commented out will not influence.I'm using apache 2.2 server of Zend . So just leave it alone.
write ur bat file
#!c:\windows\system32\cmd.exe /c
this kind of shell-like comment is not working , at the first of bat/cmd file, you need to write :
@echo off
echo Content-type: text/plain
echo.
this line above means output a new line , if u didn't do that, u will get "Premature end of script headers: xxx.bat " 500 HTTP error.
echo ^<html^>
"^" is escape character for cmd.
echo ....
the reason why ur bat not working is because that u are not stick to the HTTP protocal .
put ur bat/cmd/exe file into cgi-bin directory.
now , check it out.
advise : read the HTTP protocal.
other issues:
if u invoke other exe in ur cgi bat file such as curl.exe ,it will not work as expected,I don't know why , any information will be thanks.
- refers:http://www.jlk.net/apache/debugging_cgi.shtml
这篇关于是否有可能运行一个批处理文件与Windows下的Apache的一个CGI?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!