Webrick & CGI programs on WinXP

A

Austin Ziegler

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"
<HTML>

<HEAD>
<TITLE>Hello, world!</TITLE>
</HEAD>

<BODY>
<H1>Hello, world!</H1>
</BODY>

</HTML>
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:in `callback'
c:/Apps/Ruby18/lib/ruby/1.8/tempfile.rb:134:in `call'
c:/Apps/Ruby18/lib/ruby/1.8/tempfile.rb:99:in `close!'
c:/Apps/Ruby18/lib/ruby/1.8/tempfile.rb:90:in `close'
c:/Apps/Ruby18/lib/ruby/1.8/webrick/httpservlet/cgihandler.rb:59:in
`do_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:in
`service'
c:/Apps/Ruby18/lib/ruby/1.8/webrick/httpserver.rb:92:in `service'
c:/Apps/Ruby18/lib/ruby/1.8/webrick/httpserver.rb:54:in `run'
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:in `start'
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:in `start'
c:/Apps/Ruby18/lib/ruby/1.8/webrick/server.rb:109:in `each'
c:/Apps/Ruby18/lib/ruby/1.8/webrick/server.rb:109:in `start'
c:/Apps/Ruby18/lib/ruby/1.8/webrick/server.rb:99:in `start'
c:/Apps/Ruby18/lib/ruby/1.8/webrick/server.rb:99:in `start'
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
 
E

Eric Hodel

--jKBxcB1XkHIR0Eqt
Content-Type: text/plain; charset=us-ascii
Content-Disposition: inline
Content-Transfer-Encoding: quoted-printable
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.

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 =3D "\"#{Ruby}\" \"#{Config::LIBDIR}/httpservlet/cgi_runner.rb\""

I had to start WEBrick with a CGIInterpreter:

s =3D WEBrick::HTTPServer.new:)CGIInterpreter =3D> "\"#{WEBrick::HTTPServle=
t::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"


--=20
Eric Hodel - (e-mail address removed) - http://segment7.net
All messages signed with fingerprint:
FEC2 57F1 D465 EB15 5D6E 7C11 332A 551C 796C 9F04


--jKBxcB1XkHIR0Eqt
Content-Type: application/pgp-signature
Content-Disposition: inline

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.2 (FreeBSD)

iD8DBQE/bzngMypVHHlsnwQRAguUAKDI2Y+d5MKe3eCuKafkjSXtvioAYACeOCXB
UXqMR/1FZfHVDT9V8mFrI5A=
=ZHP3
-----END PGP SIGNATURE-----

--jKBxcB1XkHIR0Eqt--
 
G

GOTOU Yuuzou

In message said:
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")

--
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
 
G

GOTOU Yuuzou

In message said:
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.
 
J

Jim Freeze

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.
 
G

GOTOU Yuuzou

In message said:
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?
 
J

Jim Freeze

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(/^[\xd\xa]+/on, 2)
74 raise HTTPStatus::InternalServerError,
75 "The server encontered a script error." if body.nil?
76
 
G

GOTOU Yuuzou

In message said:
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(/^[\xd\xa]+/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(/^[\xd\xa]+/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;-)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,578
Members
45,052
Latest member
LucyCarper

Latest Threads

Top