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

Hello fellow perl coders,

I'm trying to find the best way to have two perl programs talk to each other. Too simple? How about in Windows? Still too simple? How about without blocking? :-)

Here's what I'm trying to do...

I'm building a robot, and I'm using Perl as the brain... or... brains, as it might be. One perl program must always be running, talking to a micro-controller via the serial port. It's important that the perl program that gathers sensor information never stop, otherwise I'll lose sensor data.

The data must be "made available" to a host of other perl processes. I was using the worst technique - writting the information to a file - but ran into problems. It felt like a hack anyhow.

I would LOVE to use shared memory, but can't find a good perl module that supports it for windows. I don't want to use Threads. I could use sockets, but I haven't had any luck telling Activestate to make a non-blocking pipe.
Thanks for any advice you may have,
- Bret

Ok, now for unnecessary detail. I currently have two perl programs for retrieving sensor data. The first communicates through a serial port to an OOPic (like a basic stamp). The second talks through a different serial port to a camera. Both write their results to files as quickly as they can.
There's another layer of "behavior" scripts, such as "avoid.pl" and "bumper.pl". These scripts read the sensor data and decide, if anything, what to do. The actions recommended by the behavior scripts are sent (via a file, again) to a central command script.
Oh boy, without big charts and drawings, it'll get too complicated to explain. Thanks again for any advice.

Replies are listed 'Best First'.
Re: Perl IPC and Windows
by kabel (Chaplain) on Sep 21, 2002 at 06:12 UTC
    generally you can pass data between two processes with socket communication (IO::Socket::INET).

    the shared memory approach is somewhat elegant; have a look here - it is called Win32::MemMap, not ShMem, as anyone (or at least i) would suggest. Tie-Win32MemMap sounds very good.

    you further can use named pipes for your purpose. the package is called Win32::Pipe.

    i could also imagine that you run the different programms as threads and let them share the needed information - as long as there is only one writing to that data and the others just reading. again: i haven't done that before.

    HTH
      Hello! Thanks for the advice. Unfortunately, I've already tried most of those ideas. Here's what I've found:

      IO::Socket::INET - The problem here is that blocking(0) doesn't work on sockets in Windows. I'm trying a work-around that was posted here.

      Win32::MemMap - This module has apparently fallen off the face of the earth. I can only find documentation for it, not the actual code. I would LOVE to use this module, if it still exists.

      Named Pipes - ..are blocking in windows. See http://aspn.activestate.com/ASPN/Reference/Products/ActivePerl/site/lib/Win32/Pipe.html under "limitations".
        this steps were taken directly from the site i pointed you:
        c:\> ppm
        PPM interactive shell (...) - type 'help' for available commands.
        PPM> set repository Jenda http://Jenda.Krynicky.cz/perl
        PPM> set save
        PPM> search
        
        the installation works for me, except the module needs Win32::API to be installed.
Re: Perl IPC and Windows
by Anonymous Monk on Sep 21, 2002 at 02:55 UTC
      What?!? Ok, I looked up Win32::IPC, but it hasn't helped me at all. It looks like it's generally loaded by Win32::Mutex, Win32::Semaphore, etc. I'm not sure how these modules will give me the functionality that I desire. Can you elaborate?