Click here to get back home

Using IPC::Open2 on Windows for mission critical app

 HomeNewsGroups | Search | About
 comp.lang.perl.misc    Post an article   get this group's latest topics as an RSS feed add this group's latest topics to your My MSN content add this group's latest topics to your My Yahoo content
Subject Author Date
Using IPC::Open2 on Windows for mission critical app Jacob JKW 06-10-2008
Posted by Jacob JKW on June 10, 2008, 6:28 am
Please log in for more thread options
I'd like to start using IPC::Open2 on Windows Vista for a mission
critical application, but I'm a little cautious based on some postings
I've read. So far I've gotten it working without a hitch and have been
unable to manufacture any errors.

The way I have it working is by opening a single external process for
read/write access local to a class that handles all interaction with
this process. If all goes well, my application during its entire
lifespan will only have one instance of this external process running.

A class method writes to the process when necessary and another method
reads from it when necessary.

The read method uses a while() loop on the read file handle and then
uses "last" to exit the loop when a specific line of text is read. I
find this a little disconcerting as if anything goes wrong with the
process the while loop will just hang indefinitely, effectively
slaughtering my application.

As a failsafe, I've tried using $SIG to no avail, as the alarm()
doesn't appear useful when reading from the file handle.

        local $SIG = sub { die "Alarm went off!\n"; };
        while(<$readFH>) {
                last if m/^END$/;
                # do stuff
        }

Does anyone have any ideas on a better failsafe? Of perhaps on a way
to get SIG ALRM working in the manner I've outlined? Or perhaps
someone could offer reassurances that the problems with IPC::Open2 on
Windows that I've hear about (which I'll reiterate that I've yet to
actually encounter) have been cleared up with new releases.

I'm currently using ActiveState binary build 820.

Posted by Ben Morrow on June 10, 2008, 10:50 am
Please log in for more thread options

>
> As a failsafe, I've tried using $SIG to no avail, as the alarm()
> doesn't appear useful when reading from the file handle.
>
>         local $SIG = sub { die "Alarm went off!\n"; };
>         while(<$readFH>) {
>                 last if m/^END$/;
>                 # do stuff
>         }

AFAIK alarm doesn't work on Win32. Probably the simplest alternative is
to create a second thread which waits for the timeout and then kills the
first thread: you will need to test to make sure that a thread waiting
for IO can be killed.

Ben

--
Heracles: Vulture! Here's a titbit for you / A few dried molecules of the gall
From the liver of a friend of yours. / Excuse the arrow but I have no spoon.
(Ted Hughes, [ Heracles shoots Vulture with arrow. Vulture bursts into ]
'Alcestis') [ flame, and falls out of sight. ] ben@morrow.me.uk

Similar ThreadsPosted
Not able to write using Open2 November 29, 2005, 2:36 pm
IPC::Open2 and sort December 9, 2006, 4:35 pm
IPC::Open2 - Bad File Descriptor March 6, 2007, 3:22 am
SIGPIPE delay on open2 exec failure April 15, 2005, 3:24 pm
windows program return values vs perl return values from a call to system() -- windows post only October 29, 2005, 6:22 pm
Windows CE, Windows Mobile November 27, 2006, 4:08 pm
Tar on Windows XP January 29, 2007, 5:27 pm
XML-RPC on Windows July 17, 2007, 11:24 am
SSH on windows September 10, 2007, 9:48 pm
Anyone using IPC::Cmd on Windows? May 5, 2008, 8:39 am

Our other projects:

Art Dolls, Fairies and Mermaids - Sunnyfaces.net

Roy's Linux, Programming and Search Engines messages

1-Script XML SitemapXML Sitemap