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

I must have written 20 different routines in 12 years to run a system command. Most of them are pretty standard, they spawn a command, then analyze both $? and $!, and if $? has a value, analyze it to find what happened. Maybe handles some I/O redirection, using callbacks if we're fancy.

It's just one of the lame things my coworkers and I have to confess to. Despite the sheer number of times we all do this, we've never put it in one central location. Time to fix that mistake

So I'm formalizing something for us. I've looked a little at using IPC::Run as a base, but I'm wondering if anyone has a tutorial for it? It's documentation is extensive, but the module is so vast, i would learn better with good examples

The other questions would be:

Thanks Brothers!


Replies are listed 'Best First'.
Re: Complete solution for system commands?
by GrandFather (Saint) on Jul 03, 2006 at 05:15 UTC
Re: Complete solution for system commands?
by Moron (Curate) on Jul 03, 2006 at 09:36 UTC
    Even though IPC::Run3 is the most official way, I usually prefer to write a wrapper class around IPC::Open3, so as to provide full control over the pipes and create sufficient flexibility for having one central solution. This depends on the requirements you want to support, but, for example, you might want to fetch just some output into memory and conditionally abort. You might want to process and submit the output from one spawned process before conditionally submitting to a second one and so on. It takes some careful design to be able to cover all the possibilities that may be necessary for a site.


    Free your mind