对于ruby/webrick,我需要使用窗口来识别shebang(#!)表示法 [英] For ruby/webrick, I need windows to recognize shebang (#!) notation

查看:108
本文介绍了对于ruby/webrick,我需要使用窗口来识别shebang(#!)表示法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

(与我同住,我保证这会影响到shebang和windows.)

(Bear with me, I promise this gets to shebang and windows.)

我将最简单的WEBRick服务器放在一起:

I have about the simplest of WEBRick servers put together:

require 'webrick'
include WEBrick

s = HTTPServer.new(:Port=>2000, :DocumentRoot=>Dir::pwd)
s.start

再简单不过了.这个基本的服务器确实接受http连接(firefox,Internet exploder,wget,TELENT)并适当地处理它们,只要我只是在获取静态文档即可.但是,如果我将目录中的文件之一设置为.cgi扩展名,则会在服务器的终端上返回500,并返回以下内容:

Couldn't be simpler. This basic server does accept http connections (firefox, internet exploder, wget, TELENT) and deals with them appropriately, as long as I'm just fetching static documents. If, however, I set one of the files in the directory to have a .cgi extension, I get a 500 back and the following on the server's terminal:

ERROR CGIHandler: c:/rubyCGI/test.cgi: 
C:/...[snip]...webrick/httpservlet/cgi_runner.rb:45: in 'exec': Exec format error - ...[snip]...

我已经在命令行上做了一些事情来模仿cgi_runner.rb第45行中发生的事情

I've done a few things on the command line to mimic what is going on in line 45 of cgi_runner.rb

c:\>ruby
exec "c:/rubyCGI/test.cgi"
^Z
(same error erupts)

c:\>ruby
exec "ruby c:/rubyCGI/test.cgi"
^Z
Content-type: text/html

Mares eat oats and does eat oats and I'll be home for Christmas.

很明显,WEBrick尚未清除可登陆Windows的权限.您通常对公司偏执狂感到头痛,这使我无法修改webrick,因此我能否在OS(Windows)识别的c:/rubyCGI/test.cgi中获得shebang表示法,所以不必每次都明确地告诉它我可以使用哪个解释器?我可以将所有.cgi文件分配为与ruby相关联,但是从长远来看,这将是一个限制.

Clearly, WEBrick hasn't been cleared for landing on windows. Your usual headaches of corporate paranoia prevent me from modifying webrick, so can I get the shebang notation in c:/rubyCGI/test.cgi recognized by the OS (windows) so I don't have to explicitly tell it each time which interpreter to use? I could assign all .cgi files to be associated with ruby, but that would be limiting in the long run.

更新: 自发布以来,我想到根本无法从ruby运行cgi Web服务器.红宝石没有分叉支持.由于无法派生一个进程,因此cgi服务器必须一次执行每个cgi脚本,而在第一个请求完成时忽略所有并发请求.虽然这对于某些人来说可以接受,但不适用于我的应用程序.不过,我仍然对我最初的问题(使shebang在Windows下工作)的答案非常感兴趣.

UPDATE: Since posting this, it has occurred to me that it may not be possible at all to run a cgi web server from ruby; ruby has no forking support. With no ability to fork a process, a cgi server would have to execute each cgi script one-at-a-time, neglecting all concurrent requests while the first one completed. While this may be acceptable for some, it would not work for my application. Nevertheless, I would still be very interested in an answer to my original question—that of getting shebang working under windows.

推荐答案

我认为您想要的是将文件扩展名与Ruby相关联.我认为不可能在Windows上使用!#表示法,但是可以使Windows使用特定的解释器自动启动脚本(如您的第二个示例). 在这里.标题为为未关联的文件类型创建文件关联"的部分.我认为这将完成您想要做的事情.

I think what you want is to associate the file extension with Ruby. I don't think it's possible to get the !# notation to work on Windows but it is possible to get Windows to automatically launch a script with a particular interpreter (as in your second example). A good step by step discussion of what you'd want to do is here. You specifically want the section headed: "To create file associations for unassociated file types". I think that will accomplish what you're trying to do.

这篇关于对于ruby/webrick,我需要使用窗口来识别shebang(#!)表示法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆