Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl Monk, Perl Meditation
 
PerlMonks  

CGI Question . . .

by Simplicus (Monk)
on Apr 24, 2000 at 21:15 UTC ( [id://8723]=perlquestion: print w/replies, xml ) Need Help??

Simplicus has asked for the wisdom of the Perl Monks concerning the following question:

I am writing a standalone ap that takes input from users via an HTML form and posts it to a file. I need to use a CGI type interface, but I also need to burn the whole thing on a CD to run on as a standalone ap. (Hence, there is no server). In my testing so far, I can execute the script from the form (using GET), but I have to enter the pairs at the command line (offline mode). Is there any way to pipe from a page directly to a script without the use of a server?
Any help is, as always, greatly appreciated . . .

Simplicus

Replies are listed 'Best First'.
RE: CGI Question . . .
by Anonymous Monk on Apr 24, 2000 at 21:48 UTC
    Perhaps this? From "perldoc CGI" In addition to the function sets, there are a number of pragmas that you can import. Pragmas, which are always preceded by a hyphen, change the way that CGI.pm functions in various ways. Pragmas, function sets, and individual functions can all be imported in the same use() line. For example, the following use statement imports the standard set of functions and disables debugging mode (pragma -no_debug): use CGI qw/:standard -no_debug/;
Re: CGI Question . . .
by comatose (Monk) on Apr 24, 2000 at 21:54 UTC

    I think I understand what you are trying to do, but you may be taking a more difficult approach. Am I correct that you want both versions to be used via a web browser?

    Because of the interactions of the browser and the server via forms and CGI, you aren't going to be able to do it simply without different versions of your script and specific configurations made on the client browser. Of course, with perl, there's always more than one way to do it.

    Probably the solution requiring the least modification to your code would be to put everything needed on the CD.

    The CD needs to have a web server, perl, and all your scripts. If you are on Win32, have a batch file that starts the server on the CD and then get a web browser to go there. It'll be tricky no matter what, but good luck!

RE: CGI Question . . .
by random (Monk) on Apr 24, 2000 at 21:55 UTC
    Simplicus, I don't think there is a way to link a page and a CGI script without some kind of server. However, you're looking at it from the wrong angle. You should be trying to get a server on the CD. Check out MicroWeb. It's proprietary, and I've never tried it personally, but it looks like it might do the job. random
      I just checked out, and it looks like it'll do the trick. Only problem is, it's $299. Maybe I can get the company to spring for it . . .%)
      Thanks, though, you pointed me in the right direction.
      Simplicus
Re: CGI Question . . .
by chromatic (Archbishop) on Apr 25, 2000 at 00:02 UTC
    The easiest solution in my mind is to use a small, Perl-based web server that could run on the client machine. Jon Udell's dhttp or my Jellybean might fit the bill. Optionally, you might write your own, using IO::Socket (as Jon did) or HTTP::Daemon (as I did, when I got tired of Sockets).

    I say it's an easy solution 'cuz I've already done it a couple of times. :)

RE: CGI Question . . .
by Keighvin (Novice) on Apr 25, 2000 at 03:37 UTC
    On the theme of good small servers, try www.sambar.com - free for personal use, etc. It's an awesome little server anyway (for Win32).
      Thanks, and I gave you the vote here for your anonymous HTML 1.0 Facelift post . . .
      Simplicus
RE: CGI Question . . .
by random (Monk) on Apr 24, 2000 at 21:58 UTC
    Simplicus, I don't think there is a way to link a page and a CGI script without some kind of server. However, you're looking at it from the wrong angle. You should be trying to get a server on the CD. Check out MicroWeb. It's proprietary, and I've never tried it personally, but it looks like it might do the job. random
Re: CGI Question . . .
by httptech (Chaplain) on Apr 25, 2000 at 00:11 UTC
    If the target platform is Win32 you can use TinyWeb It will run off of the CD, with no config file necessary. It's written in Delphi, and the source is available. I am also trying to make a "CGI on CD" system, and am planning to use TinyWeb as the server. The executable is around 53K, and it runs CGI. And it's freeware.

    One small thing I didn't like about it is it keeps access, error and referrer logs, with no commandline switch to disable them. I solved it by removing all logging routines from the source code (it was fairly simple, and I know nothing about Delphi programming)

    For the perl scripts themselves, I am compiling them into standalone executables with perl2exe (which does cost money)

      I've used perlapp from ActiveState in the past. It sure as hell would fit a job like the one described to build freestanding executables... They seem to be alot more stable and less "chunkier" than the fully compiled *NIX executables.

      At least I haven't had any freestanding apps core dump on me yet... Its worth the money (plus you a get a nice debugger).

      Cheers.
RE: CGI Question . . .
by da'ud (Initiate) on Apr 25, 2000 at 07:58 UTC
    it's really quite simple (as far a I can see). Making a webserver in perl is _extremely_ simple.

    So just put a few minimal perl distributions on the disk (one per platform you want to support) and put a script similar to the following (adopted from HTTP::Daemon pod):

    use HTTP::Daemon; use HTTP::Status; my $d = new HTTP::Daemon LocalPort => 9999; print "CDRom webserver running on: ", $d->url, "\n"; while (my $c = $d->accept) { while (my $r = $c->get_request) { if ($r->method eq 'GET') { # here you do the stuff # ... } else { $c->send_error(RC_FORBIDDEN) } } $c->close; undef($c); }
    then you make a few ways to start the server (autorun on win32, ...) and you are up and away.

    think perl for perl is the most elevated

    your humble brother

    /dh

RE: CGI Question . . .
by Simplicus (Monk) on Apr 25, 2000 at 18:02 UTC
    Thanks to all of you, my friends. I'm using HTTP::daemon to write a small web server now, since I have to port this to UNIX and Windows. Couldn't have done it without you, thanks again for the help . . .
    Simplicus
RE: CGI Question . . .
by BoxCarWillie (Initiate) on Apr 25, 2000 at 04:44 UTC
    --- put your name value pairs inside a text file eg. v.txt
    a=20
    b=30
    arg=40
    
    If t.pl is your script then execute as t.pl  < v.txt
    
    sample :
    use CGI; my $page=new CGI ; if (! $page->param() ) { print ".. will NOT read from STDIN\n"; } else { print ".. will read from STDIN\n"; foreach ( $page->param () ) { print "$_ = @{[$page->param ($_)]}\n"; } }
    results:
    (offline mode: enter name=value pairs on standard input)
    .. will read from STDIN
    a = 20
    y = 30
    arg = 40
    
    Note: for more powerful solutions you may want to look at how the function read_from_cmdline in CGI.pm is used and called and what it does.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://8723]
Approved by root
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others perusing the Monastery: (3)
As of 2024-04-25 10:18 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found