Cgi scripts don't know hostname

Forgive me if this is a dumb question, but it’s got me stumped.

I’m running a WEBrick server and I’ve mounted HTTPServlet::FileHandler
as follows:

s.mount("/cgi-bin",HTTPServlet::FileHandler,
cgi_dir,{:FancyIndexing=>true})

However, the scripts in the cgi-bin directory can’t find the hostname
when they’re run by the web server. E.g., the following script

#!/usr/bin/ruby -w

s = %{


Hi #{ENV[‘HOSTNAME’]} Bye


}
print s

prints the html with the machine name embedded in it when I run it from
the command line, but only “Hi Bye” when I look at it in the browser.
What’s up with that?

It turns out that the cgi scripts run this way have an empty or at least
incomplete ENV. I worked around it by marshaling the server’s ENV and
having
the cgi’s read it at startup. Not a great solution, but it works.

Mark P. wrote:

Forgive me if this is a dumb question, but it’s got me stumped.

I’m running a WEBrick server and I’ve mounted HTTPServlet::FileHandler
as follows:

s.mount("/cgi-bin",HTTPServlet::FileHandler,
cgi_dir,{:FancyIndexing=>true})

However, the scripts in the cgi-bin directory can’t find the hostname
when they’re run by the web server. E.g., the following script

#!/usr/bin/ruby -w

s = %{


Hi #{ENV[‘HOSTNAME’]} Bye


}
print s

prints the html with the machine name embedded in it when I run it from
the command line, but only “Hi Bye” when I look at it in the browser.
What’s up with that?

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs