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

I am about to make blatantly obvious my lack of experience with having Perl communicate with external programs. I am not specifically looking for info on security or usefulness in this matter (although any such advice you offer will be gratefully accepted), rather I seek enlightenment on the general possibilities.

Here's what I am seeking to know... is it possible to have a Perl script start up and communicate with another Perl script which was already previously running on the server? For instance, I might have a continually running script on the server (Script_A) which just takes data on the STDIN and spits out responses without terminating-- and I want my CGI script (Script_B) to send it a string, collect the output, manipulate it, send it to the user, and shut down... and Script_A just quietly waits for the next request. Possible?

Thanks for any data, folks.

Alan "Hot Pastrami" Bellows
-Sitting calmly with scissors-

Replies are listed 'Best First'.
Re: Another forking question!
by chromatic (Archbishop) on Aug 24, 2000 at 02:14 UTC
    Extremely possible. You could do it via any number of methods mentioned in perldoc perlipc -- named pipes, sockets, anonymous pipes via fork.

    I'd look into named pipes, in this case, as they're extremely simple to use (if you're on a Unixy machine), and don't require learning or doing many new things. (Not that learning is bad, but start simple.)

RE: Another forking question!
by merlyn (Sage) on Aug 24, 2000 at 02:37 UTC
    If the "already running" script can be strictly in a "serve all comers" mode, and not working on things independantly, you can create a "mini-web-server" using a couple of my WebTechniques Perl Columns as examples: in particular the ones on "the doctor is in (part 1/2)".

    As a remote procedure call protocol on top of that, consider SOAP or WDDX, both in the CPAN.

    -- Randal L. Schwartz, Perl hacker

      If you want something like this but a bit simpler you could try PlRPC.

      This is much more perl specific than the modules merlyn mentioned though.

Re: Another forking question!
by Maclir (Curate) on Aug 24, 2000 at 02:36 UTC
    Not sure if this is exactly what you want, but using sockets (and IO::Socket) may be a possibility. Look at Chapter 17 of the "Perl Cookbook".