2014-07-03 115 views
0

我试图运行我的jscript文件并将结果返回给使用CGI的客户端。但是我不能像#!/ usr/bin/cscript.exe那样设置第一行或者第一行,因为jscript不支持#开始的注释并且出错。Apache在Windows上更改CGI解释器

问题:如何在我的脚本的第一行没有!#/ usr/bin/cscript.exe的情况下设置我的CGI解释器的路径?

回答

1

从我相当陈旧的httpd.conf:

# However, Apache on Windows allows either the Unix behavior above, or can 
# use the Registry to match files by extention. The command to execute 
# a file of this type is retrieved from the registry by the same method as 
# the Windows Explorer would use to handle double-clicking on a file. 
# These script actions can be configured from the Windows Explorer View menu, 
# 'Folder Options', and reviewing the 'File Types' tab. Clicking the Edit 
# button allows you to modify the Actions, of which Apache 1.3 attempts to 
# perform the 'Open' Action, and failing that it will try the shebang line. 
# This behavior is subject to change in Apache release 2.0. 
# 
# Each mechanism has it's own specific security weaknesses, from the means 
# to run a program you didn't intend the website owner to invoke, and the 
# best method is a matter of great debate. 
# 
# To enable the this Windows specific behavior (and therefore -disable- the 
# equivilant Unix behavior), uncomment the following directive: 
# 
#ScriptInterpreterSource registry 

所以我启用了ScriptInterpreterSource功能,检查:

ftype JSFile 
JSFile=%SystemRoot%\System32\CScript.exe "%1" %* 

和使用c:\programme\xampp\cgi-bin\jscgi.js包含:

WScript.Echo("Content-Type: text/html\n"); 
WScript.Echo("OK:", WScript.ScriptFullName, new Date()); 

成功。我没有触及像AddHandler,目录或 ScriptAlias等其他设置,并且我刚刚测试了phpinfo.php和printenv.pl,看看这个 更改是否破坏了我的安装 - 没有。

你应该更谨慎。

更新WRT评论:

按照2.4的文档(搜索 “ScriptInterpreterSource”)的指令仍然有效。您确定apache用户帐户与cscript.exe关联.js文件吗?

+0

您使用的是哪个版本的Apache?我正在Apache/2.4.4上尝试相同的设置,但它不起作用 – arzzzen

+0

@arzzzen - 请参阅更新。 –