Webrick & CGI programs on WinXP

I’m attempting to get ruwiki running under WEBrick on Windows XP. It’s not
working, so I am attempting with a very simple CGI script. Well, that isn’t
working, either.

I’m starting WEBrick with:

···

#!/usr/local/bin/ruby
require 'webrick’
include WEBrick

s = HTTPServer.new(:Port => 2000, :DocumentRoot => Dir::pwd + “/htdocs”)

# mount subdirectories

s.mount("/ruwiki", HTTPServlet::CGIHandler, “C:/Apps/Ruby18/bin/ruby.exe”)

trap(“INT”){ s.shutdown }
s.start

My CGI script is currently called hello.rb, but I’ve tried it as hello.cgi
as well and it doesn’t work:

#!C:/Apps/Ruby18/bin/ruby.exe

hello.pl – my first perl script!

print “Content-type: text/html\n\n”

print <<“EOF”

Hello, world!

Hello, world!


EOF

Here’s the error message:
[2003-09-22 13:00:11] INFO WEBrick 1.3.1
[2003-09-22 13:00:11] INFO ruby 1.8.0 (2003-08-04) [i386-mswin32]
[2003-09-22 13:00:11] INFO WEBrick::HTTPServer#start: pid=3268 port=2000
[2003-09-22 13:00:20] ERROR Errno::EACCES: Permission denied -
C:\DOCUME~1\Austin\LOCALS~1\Temp/webrick.cgiout.3268.0
c:/Apps/Ruby18/lib/ruby/1.8/tempfile.rb:143:in unlink' c:/Apps/Ruby18/lib/ruby/1.8/tempfile.rb:143:incallback’
c:/Apps/Ruby18/lib/ruby/1.8/tempfile.rb:134:in call' c:/Apps/Ruby18/lib/ruby/1.8/tempfile.rb:99:inclose!'
c:/Apps/Ruby18/lib/ruby/1.8/tempfile.rb:90:in close' c:/Apps/Ruby18/lib/ruby/1.8/webrick/httpservlet/cgihandler.rb:59:indo_GET’
c:/Apps/Ruby18/lib/ruby/1.8/webrick/httpservlet/abstract.rb:35:in
__send__' c:/Apps/Ruby18/lib/ruby/1.8/webrick/httpservlet/abstract.rb:35:inservice’
c:/Apps/Ruby18/lib/ruby/1.8/webrick/httpserver.rb:92:in service' c:/Apps/Ruby18/lib/ruby/1.8/webrick/httpserver.rb:54:inrun’
c:/Apps/Ruby18/lib/ruby/1.8/webrick/server.rb:168:in start_thread' c:/Apps/Ruby18/lib/ruby/1.8/webrick/server.rb:162:instart’
c:/Apps/Ruby18/lib/ruby/1.8/webrick/server.rb:162:in start_thread' c:/Apps/Ruby18/lib/ruby/1.8/webrick/server.rb:114:instart’
c:/Apps/Ruby18/lib/ruby/1.8/webrick/server.rb:109:in each' c:/Apps/Ruby18/lib/ruby/1.8/webrick/server.rb:109:instart’
c:/Apps/Ruby18/lib/ruby/1.8/webrick/server.rb:99:in start' c:/Apps/Ruby18/lib/ruby/1.8/webrick/server.rb:99:instart’
c:/tmp/webrick/server.rb:13
localhost - - [22/Sep/2003:13:00:19 Eastern Daylight Time] “GET
/ruwiki/hello.rb HTTP/1.1” 500 354

  • -> /ruwiki/hello.rb

-austin

austin ziegler * austin@halostatue.ca * Toronto, ON, Canada
software designer * pragmatic programmer * 2003.09.22
* 12.44.34

I’m attempting to get ruwiki running under WEBrick on Windows XP. It’s
not working, so I am attempting with a very simple CGI script. Well,
that isn’t working, either.

I am having similar issues as well. I have uninstalled ruby, deleted
the directory tree, and reinstalled the latest prag-prog install. No
help. After looking in the archives I added a few things to the
configuration :

:CGIInterpreter => “ruby”

to the constructor block

and then

file_handler_opt = { :HandlerTable =>
Hash.new(WEBrick::HTTPServlet::CGIHandler) }

s.mount(“/cgi-bin”, WEBrick::HTTPServlet::FileHandler,
<cgi_dirctory>, file_handler_opt)

I no longer get the error, but I also get no output.

I am still looking into it, but there does seem to be something awry
somewhere.

Walt

···

Walter Szewelanczyk
IS Director
M.W. Sewall & CO. email : walter@mwsewall.com
259 Front St. Phone : (207) 442-7994 x 128
Bath, ME 04530 Fax : (207) 443-6284


WEBrick has too many UNIX-isms to work well on a microsoft platform,
I’ve got it working though.

In cgihandler.rb add ``<< ::Conifg::CONFIG[‘EXEEXT’]‘’ to line 21, so
the correct name of the ruby interpreter is used.

I had to add quotes to line 22 to use the correct path, because my ruby
is installed in a non-standard location:

CGIRunner = “"#{Ruby}" "#{Config::LIBDIR}/httpservlet/cgi_runner.rb"”

I had to start WEBrick with a CGIInterpreter:

s = WEBrick::HTTPServer.new(:CGIInterpreter => “"#{WEBrick::HTTPServlet::CGIHandler::Ruby}"”)

I was then able to use a CGI:

s.mount(“/hi”, WEBrick::HTTPServlet::CGIHandler. “cgi.rb”)

where cgi.rb was:

print “content-type: text/plain\r\n\r\n”

puts “hi”

···

Austin Ziegler (austin@halostatue.ca) wrote:

I’m attempting to get ruwiki running under WEBrick on Windows XP. It’s not
working, so I am attempting with a very simple CGI script. Well, that isn’t
working, either.


Eric Hodel - drbrain@segment7.net - http://segment7.net
All messages signed with fingerprint:
FEC2 57F1 D465 EB15 5D6E 7C11 332A 551C 796C 9F04

I’m attempting to get ruwiki running under WEBrick on Windows XP. It’s not

working, so I am attempting with a very simple CGI script. Well, that isn’t

working, either.

···

On Tue, 23 Sep 2003, Austin Ziegler wrote:

This doesn’t really answer your specific question, but an alternative
would be to not use CGI, but instead create a Webrick servlet. I use
Webrick with Dave Thomas’s RubLog package on my WinXP machine at home. This worked pretty well for Rublog without a
ton of duplication, because the CGI for RubLog was really just a thin
wrapper/configurator on top of a set of libraries.

You can see the trivial Webrick code here:

http://cvs.sourceforge.net/cgi-bin/viewcvs.cgi/rublog/rublog/extras/webrick/rublog_servlet.rb?rev=1.2&content-type=text/vnd.viewcvs-markup

Chad

In message 200392213938.486535@PADD,

I’m attempting to get ruwiki running under WEBrick on Windows XP. It’s not
working, so I am attempting with a very simple CGI script. Well, that isn’t
working, either.

I’m starting WEBrick with:

#!/usr/local/bin/ruby
require ‘webrick’
include WEBrick

s = HTTPServer.new(:Port => 2000, :DocumentRoot => Dir::pwd + “/htdocs”)

# mount subdirectories

s.mount(“/ruwiki”, HTTPServlet::CGIHandler, “C:/Apps/Ruby18/bin/ruby.exe”)

trap(“INT”){ s.shutdown }
s.start

Could you apply the attached patch? And if same error
occurs again, please increase the sleep time. (Windows
doesn’t allow deleting opened files. This patch makes it
delay to wait for exiting of child process.)

and try it.

require 'webrick'
include WEBrick
s = HTTPServer.new(
  :Port => 2000,
  :DocumentRoot => Dir::pwd + "/htdocs",
  :CGIInterpreter => "C:/Apps/Ruby18/bin/ruby.exe"
)
s.mount("/rwiki", HTTPServlet::FileHandler, "/path/of/script-dir")
s.start

When CGIHandler is mounted on server directly, third
argument of mount() is expexted to be a pathname of script.

s.mount("/rwiki", HTTPServlet::CGIHandler, "/path/of/script.cgi")
···

`Austin Ziegler austin@halostatue.ca’ wrote:


gotoyuzo

diff -u -p -r1.1 cgihandler.rb
— lib/webrick/httpservlet/cgihandler.rb 23 Jul 2003 16:51:36 -0000 1.1
+++ lib/webrick/httpservlet/cgihandler.rb 22 Sep 2003 18:17:52 -0000
@@ -55,6 +55,7 @@ module WEBrick
ensure
cgi_in.close
status = $? >> 8

  •      sleep 0.1
         data = cgi_out.read
         cgi_out.close(true)
         if errmsg = cgi_err.read
    

In message 20030922180520.GE63282@segment7.net,

WEBrick has too many UNIX-isms

Yes, but I don’t hope it;-)

In cgihandler.rb add ``<< ::Conifg::CONFIG[‘EXEEXT’]‘’ to line 21, so
the correct name of the ruby interpreter is used.

I had to add quotes to line 22 to use the correct path, because my ruby
is installed in a non-standard location:

CGIRunner = “"#{Ruby}" "#{Config::LIBDIR}/httpservlet/cgi_runner.rb"”

I’ll merge these fix. Thanks.

···

`Eric Hodel drbrain@segment7.net’ wrote:


gotoyuzo

After merging Eric’s and gotoyuzo’s patches, the script runs … but
produces a 500 error and nothing in the log. I had already pretty much
reached the decision to implement this as a servlet, but it seems that the
CGI interface on Windows still needs some work. I may look at it a bit later
– I am more interested in getting RuWiki working with WEBrick in any way
that I can so that the possibilities for RuWiki are greater.

-austin

···


austin ziegler * austin@halostatue.ca * Toronto, ON, Canada
software designer * pragmatic programmer * 2003.09.22
* 16.02.52

That is the same error that I get on Sun. So it looks like
you have at least put XP on par with Unix.

···

On Tuesday, 23 September 2003 at 5:11:34 +0900, Austin Ziegler wrote:

After merging Eric’s and gotoyuzo’s patches, the script runs … but
produces a 500 error and nothing in the log. I had already pretty much
reached the decision to implement this as a servlet, but it seems that the
CGI interface on Windows still needs some work. I may look at it a bit later
– I am more interested in getting RuWiki working with WEBrick in any way
that I can so that the possibilities for RuWiki are greater.


Jim Freeze

Satellite Safety Tip #14:
If you see a bright streak in the sky coming at you, duck.

In message 20030922163701.A26801@freeze.org,

···

`Jim Freeze jim@freeze.org’ wrote:

On Tuesday, 23 September 2003 at 5:11:34 +0900, Austin Ziegler wrote:

After merging Eric’s and gotoyuzo’s patches, the script runs … but
produces a 500 error and nothing in the log. I had already pretty much
reached the decision to implement this as a servlet, but it seems that the
CGI interface on Windows still needs some work. I may look at it a bit later
– I am more interested in getting RuWiki working with WEBrick in any way
that I can so that the possibilities for RuWiki are greater.

That is the same error that I get on Sun. So it looks like
you have at least put XP on par with Unix.

Could you get error message with ruby -v?


gotoyuzo

Good idea.
I get the following:

Exception `WEBrick::HTTPStatus::InternalServerError’ at
/tools/apps/ruby/ruby-1.8.0/lib/ruby/site_ruby/1.8/webrick/httpservlet/cgihandler.rb:75

  • The server encontered a script error.
    afropuff.mis.cypress.com - - [23/Sep/2003:09:45:58 EDT] “GET /ruwiki.cgi
    HTTP/1.1” 500 334

  • → /ruwiki.cgi

    72 data = “” unless data
    73 raw_header, body = data.split(/[1]+/on, 2)
    74 raise HTTPStatus::InternalServerError,
    75 “The server encontered a script error.” if body.nil?
    76

···

On Tuesday, 23 September 2003 at 22:34:07 +0900, GOTOU Yuuzou wrote:

In message 20030922163701.A26801@freeze.org,
`Jim Freeze jim@freeze.org’ wrote:

On Tuesday, 23 September 2003 at 5:11:34 +0900, Austin Ziegler wrote:

After merging Eric’s and gotoyuzo’s patches, the script runs … but
produces a 500 error and nothing in the log. I had already pretty much
reached the decision to implement this as a servlet, but it seems that the
CGI interface on Windows still needs some work. I may look at it a bit later
– I am more interested in getting RuWiki working with WEBrick in any way
that I can so that the possibilities for RuWiki are greater.

That is the same error that I get on Sun. So it looks like
you have at least put XP on par with Unix.

Could you get error message with ruby -v?


Jim Freeze


  1. \xd\xa ↩︎

In message 20030923094845.A32994@freeze.org,

Could you get error message with ruby -v?

Good idea.
I get the following:

Exception `WEBrick::HTTPStatus::InternalServerError’ at
/tools/apps/ruby/ruby-1.8.0/lib/ruby/site_ruby/1.8/webrick/httpservlet/cgihandler.rb:75

  • The server encontered a script error.
    afropuff.mis.cypress.com - - [23/Sep/2003:09:45:58 EDT] “GET /ruwiki.cgi
    HTTP/1.1” 500 334

  • → /ruwiki.cgi

    72 data = “” unless data
    73 raw_header, body = data.split(/[1]+/on, 2)
    74 raise HTTPStatus::InternalServerError,
    75 “The server encontered a script error.” if body.nil?
    76

ary = [ “”, “\n”, “foo: bar”, “foo: bar\n”, “foo:bar\n\n” ]
ary.each{|data|
a, b = data.split(/[2]+/on, 2)
p [ data, a, b ]
}

result is:

[“”, nil, nil]
[“\n”, “”, “”]
[“foo: bar”, “foo: bar”, nil]
[“foo: bar\n”, “foo: bar\n”, nil]
[“foo:bar\n\n”, “foo:bar\n”, “”]

It seems that output of CGI is empty or doesn’t include
separator of headers and message-body.
It may be that WEBrick couldn’t get CGI output correctly;-)

···

`Jim Freeze jim@freeze.org’ wrote:

On Tuesday, 23 September 2003 at 22:34:07 +0900, GOTOU Yuuzou wrote:


gotoyuzo


  1. \xd\xa ↩︎

  2. \xd\xa ↩︎