2

I have using Webrick + CGI and when I instantiate, returns an error: (offline mode: enter name=value pairs on standard input)

irb(main):001:0> require 'cgi'
=> true
irb(main):002:0> cgi = CGI.new
(offline mode: enter name=value pairs on standard input)
Darlan Dieterich
  • 2,369
  • 1
  • 27
  • 37

1 Answers1

5

Nope, not an error. That's the way it works.

From the ruby-docs CGI documentation

If the CGI object is not created in a standard CGI call environment (that is, it can’t locate REQUEST_METHOD in its environment), then it will run in “offline” mode. In this mode, it reads its parameters from the command line or (failing that) from standard input

In the irb console, after the (offline mode: enter name=value pairs on standard input) message, the console is waiting for you to enter the values. Enter key value pairs followed by Ctrld to finish entering data.

 irb(main):001:0> require 'cgi'
 => true
 irb(main):002:0> cgi = CGI.new
 (offline mode: enter name=value pairs on standard input)
 name=Prakash
 number=432

Ctrld

 => #<CGI:0x007fa4eb2abd30 @options={:accept_charset=>"UTF-8"}, @accept_charset="UTF-8", @multipart=false, @params={"name"=>["Prakash"], "number"=>["432"]}, @cookies={}, @output_cookies=nil, @output_hidden=nil> 
irb(main):003:0>

Refer to CGI Programming Documentation on PLEAC-Ruby for further code examples of working with CGI in ruby.

Prakash Murthy
  • 12,923
  • 3
  • 46
  • 74
  • Ihave using Win7 + Webrick server, my code is: <% Encoding.compatible?("\xa1".force_encoding("iso-8859-1"), "b") %> Sessão

    zezzão

    <% require "cgi" require "cgi/session" cgi = CGI::new session = CGI::Session.new(cgi,"prefix"=>"rubysession") session["name"]="Darlan" %> <%= "Oi, #{session["name"]}"%> <% session.close session.delete %>
    – Darlan Dieterich Feb 18 '13 at 13:41
  • Every time I use CRTL + D? – Darlan Dieterich Feb 20 '13 at 21:27