in reply to (Ovid - CGI or command line?) Re(3): Prompting user input (newbie)
in thread Prompting user input (newbie)

I was just trying to get an input line and capture the input as a string in a simple little CGI script. I only know a little about CGI scripts, and don't know about command line programs. Obviously the following bit of code doesn't have the means to accept input:
#!/usr/bin/perl use CGI qw/:standard/; $q=new CGI; print $q->header; print "Enter something: "; my $response = <STDIN>; print "You just entered: $response";
So my question is two-fold: Can a CGI script accept user input other than from an HTML-based form? Secondly, how might I find out about command line program functionality? Laura
  • Comment on Re: (Ovid - CGI or command line?) Re(3): Prompting user input (newbie)
  • Download Code

Replies are listed 'Best First'.
Re:(Maclir) Re: (Ovid - CGI or command line?) Re(3): Prompting user input (newbie)
by Maclir (Curate) on Apr 27, 2001 at 02:55 UTC
    Laura,

    What you need to understand is how the CGI process works. You have a slightly different environment to the traditional unix shell setup. While STDOUT certainly exists - if your CGI program is generating a web page "on the fly", STDOUT is what is passed back to the web server, and then to the user's browser.

    What you do have is (and I will try to show it diagramatically):

    User ======> Web Server =====> (CGI request via GET requests sees CGIExec or POST) URL page type * program gets paramaters * generates web page ohhahh<===== sends page <===== * sends page through STDOUT users back in the sees my standard http wonderful manner generated page
    So the only way for the user to interact with the cgi program is via values passed to the browser, either as part of the url (the GET method) or associated in a pseudo file (POST). If you are using CGI.pm (the recommended way), then these values are presented to your CGI program in a consistent, easy to access way.

    Hope this helps. You can look at the CGI.pm documentation at http://stein.cshl.org/WWW/software/CGI/cgi_docs.html - Lincoln Stein is probably the expert on CGI perl programs.

      OKeedokee, thanks so much for the explanation (I realize I was barking up the wrong tree...)
      laura