Displaying the html from a ruby .cgi script

I have a script, foobar.cgi

I can load it into my browser, as in
http://localhost/foobar.cgi

It generates html code. I am using Apache on Linux here,
everything is local only.

My question is:

Is there an easy way to grab that generated html code and
display it (as a long string) on a console?

I thought lynx -dump might help but it doesn’t, plus it is
not a “ruby only” solution, which I would prefer (since
I’d like this to work on windows as well, even without
lynx around)

Marc H. wrote:

I have a script, foobar.cgi

I can load it into my browser, as in
http://localhost/foobar.cgi

[…]
Is there an easy way to grab that generated html code and
display it (as a long string) on a console?
[…]
a “ruby only” solution, which I would prefer

require ‘open-uri’
print open(‘http://localhost/foobar.cgi’).read

I thought lynx -dump might help but it doesn’t,

What does “it doesn’t” mean? If it means “but I don’t see the HTML”,
then that because you should’ve used -source, not -dump.

On Dec 22, 2009, at 14:49 , Marc H. wrote:

Is there an easy way to grab that generated html code and
display it (as a long string) on a console?

% ruby foobar.cgi < /dev/null

Marc H. wrote:

I have a script, foobar.cgi

I can load it into my browser, as in
http://localhost/foobar.cgi

It generates html code. I am using Apache on Linux here,
everything is local only.

My question is:

Is there an easy way to grab that generated html code and
display it (as a long string) on a console?

(1) curl http://localhost/foobar.cgi

With appropriate command-line options you can also POST to the CGI
easily enough. (Maintaining a session with cookies would be more awkward
though)

(2) I believe you should just be able to run the CGI from the command
line:

/path/to/foobar.cgi
or
ruby /path/to/foobar.cgi

in which case it’ll prompt you for any parameters, then press ^D to get
the response.

(3) The very manual way:

telnet localhost 80
GET /foobar.cgi HTTP/1.0
Host: localhost

Thanks for the help, works nicely!

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