How to use htmlextension of cgi class?

L

lahirister

Hi,
Can anyone please say what is wrong with this code:

require "cgi"
index = CGI.new("html3")

if (! FileTest.exists?("config.ini")) then
index.out{"Cannot find config.ini file"}
exit
end

print index.a("http://www.example.com"){ "Example" }


What is wrong with the last line. When I execute this through the web
browser I can see in the error logs:
[Tue Nov 01 23:22:03 2005] [error] [client 10.38.0.15] Premature end of
script headers: index.cgi

Thanks
Depp
 
B

Brian Schröder

Hi,
Can anyone please say what is wrong with this code:

require "cgi"
index =3D CGI.new("html3")

if (! FileTest.exists?("config.ini")) then
index.out{"Cannot find config.ini file"}
exit
end

print index.a("http://www.example.com"){ "Example" }


What is wrong with the last line. When I execute this through the web
browser I can see in the error logs:
[Tue Nov 01 23:22:03 2005] [error] [client 10.38.0.15] Premature end of
script headers: index.cgi

Thanks
Depp

Assuming that your config.ini exists we can shorten the example to
require "cgi"
index =3D CGI.new("html3")
print index.a("http://www.example.com"){ "Example" }

now if you execute this via the commandline you see this output
$ ruby test.cgi
(offline mode: enter name=3Dvalue pairs on standard input)^D
<A HREF=3D"http://www.example.com">Example</A>bschroed@oerfi:~/svn/projekte=
/ruby-things$

where one can see that the header lines are missing. Change the above to:

-----
#!/usr/bin/ruby

require "cgi"
index =3D CGI.new("html3")

index.out do
index.a("http://www.example.com"){ "Example" }
end
------

and the output becomes
-------
Content-Type: text/html
Content-Length: 44

<A HREF=3D"http://www.example.com">Example</A>
-------

This should work as a cgi script.

hope to help,

Brian
 

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

Forum statistics

Threads
474,184
Messages
2,570,979
Members
47,579
Latest member
CharaS3188

Latest Threads

Top