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

is it possible to send data directly between CGI scripts that are running? i know i could use files to do it indirectly, but i'd rather not do that.

i've tried pipes, but unsuccessfully. i keep getting
"The name specified is not recognized as an internal or external command, operable program or batch file."
as my error message. i've tried:

open (LOGIN, "| ./login.pl") or die "can't login $!";
and
open (LOGIN, "| login.pl") or die "can't login $!";

does anyone know how to get this to work?

Replies are listed 'Best First'.
RE: sending data between CGI scripts
by jjhorner (Hermit) on Jul 18, 2000 at 17:53 UTC

    CGI scripts aren't always running. If you want to send data from one CGI script to another, you will have to call the CGI script with the appropriate parameters. CGI scripts are only run when requested. They aren't daemons or services.

    Now, if you are wondering how to send data from one script to another, not running as CGIs, you have it about right above.

    You may want to specify the full path in your open command, though.

    J. J. Horner
    Linux, Perl, Apache, Stronghold, Unix
    jhorner@knoxlug.org http://www.knoxlug.org/
    
(jcwren) Re: sending data between CGI scripts
by jcwren (Prior) on Jul 18, 2000 at 17:53 UTC
    I'm a little unclear on what you're trying to accomplish, here. A CGI script isn't 'running', unless someone accesses the page. You can invoke a script from your currently running script, passing commands either through STDIN (you'd have to fake looking like a webserver invoked you, most likely, to make it happy), you could invoke it with arguments on the command line, or you could invoke the script by accessing via the webserver (basically making your script look like a browser client).

    Perhaps a little more detail here, and we could give you some more useful help, or point you towards a better way to accomplish whatever is you're trying to do.

    As a side note, having a script named 'login.pl' is questionable, at best. There are certain common names that 'cracking' programs scan for, and by naming a script 'login.pl', you're inviting it to take a closer look at you. There's about a half a dozen common names you want to avoid.

    --Chris

    e-mail jcwren
      the idea is that someone requests the main script. this script then uses other scripts to get some information. the first script is running and calls the other scripts to get information. i'm not sure it'll work out the way i planned it though. as for login.pl, it was just a temporary name to give the script so i have some idea whats going on in my program... it would have been changed long before i actually used it for anything important.
        I usually use modules for this purpose. (See perlmod for groovy details.) My main CGI is pretty simple:
        #!/usr/bin/perl -wT use strict; use SuperModule; use CGI; my $q = CGI->new(); # magic here my %actions = ( login => \&do_login, post => \&do_post, pyro => \&set_someone_on_fire ); my $action = $q->param('action'); if (defined $actions{$action}) { $actions{$action}->($q); } else { default_page($q); } sub do_login { # check login parameters here my $q = shift; SuperModule::login($q); # or whatever }
        ...and so forth. It's a layer of abstraction, to be sure, but if you want to put the whole script into your httpd.conf file, it makes mod_perl'ing it a lot easier.
        If the first script needs to call other .cgi scripts, tehn you want to use LWP. If the cgi script is just calling other scripts then you can just system or open it with a pipe.
(chromatic) Re: sending data between CGI scripts
by chromatic (Archbishop) on Jul 18, 2000 at 22:31 UTC
    With the right tools, URLs can be thought of as APIs. To wit, take Perl Monks. You can use Bundle::LWP to make calls against it (as if it were a library).
    object => perlmonks.org/index.pl method => node_id parameter => <number of node to retrieve>
    Why is this important? It allows you to treat remote resources as if they were local.

    Of course, you could always use a bit of HTML form magic to accomplish what you want in this case:

    <form action=" some other cgi" method="post"> <input type="hidden" name="var1" value="whatever"> <input type="submit" name="go"> </form>