Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change

Re: Modules which improve system() ?

by jesuashok (Curate)
on Jun 23, 2006 at 08:14 UTC ( #557113=note: print w/replies, xml ) Need Help??

in reply to Modules which improve system() ?

Hi pjf

Even If I use your Some::Module qw/run/ ( I would say only 'System::Run' ) Inside the module what is your definition is going to be ? what would you use to run my unix commands like, `complicated sed commmands`,runnung another perl programs, running the commands like telnet,ftp,lpr .. etc.


How the efficiency is going to be when I use the module ( Some::Module)? what are all the factors you are going to consider for efficiency ? Or, you are going to concentrate only on returning the proper error codes and throwing the proper exvceptions.

I appreciate your good start.

"Keep pouring your ideas"

Replies are listed 'Best First'.
Re^2: Modules which improve system() ?
by pjf (Curate) on Jun 23, 2006 at 08:34 UTC

    I'm specifically after a module that makes it dead simple to call system() for the most simple cases, and still get proper error-handling. What I essentially want is Fatal for system().

    That means we're not capturing output, and we're not doing complicated pipelines. If you want a module that handles all that and more, then there's IPC::Run. It's complete, but it's not simple.

    What's proper-error handling for the most simple cases? Well, if your program never started, that's an error. If it got killed by a signal or dumped core, then you probably didn't expact that, so that's an error too. If it returns a non-zero exit status, then that's also an error unless you pass an argument to say otherwise.

    As for efficiency, this is a clear case where correctness should easily trump speed. system() is slow to begin with, since there's all that fork-and-exec'ing going on under the hood. Having error-checking that's hard to get wrong (ie, exceptions), and having meaningful error messages (instead of die "Ooops! $! - $?") is going to be much better for correctness and programmer productivity in the long run.

    This is very much a case of wanting something that makes simple things easy. We've already got many ways of making the hard things possible.


      As I just mentioned in this post, how about IPC::Run3?

      From its Pod:

      compared to system(), qx'', open "...|", open "|...": + redirects more than one file descriptor + returns TRUE on success, FALSE on failure + throws an error if problems occur in the parent process (or the +pre-exec child) + allows a very perlish interface to Perl data structures and subr +outines + allows 1 word invocations to avoid the shell easily: run3 ["foo"]; # does not invoke shell - does not return the exit code, leaves it in $?

      So you could use it like this:

      eval { run3 $program } or die "Errors running $program";

      Its docs leave a bit to be desired, but the current maintainer might be willing to take some doc patches...


      Code written by xdg and posted on PerlMonks is public domain. It is provided as is with no warranties, express or implied, of any kind. Posted code may not have been tested. Use of posted code is at your own risk.

        I concur with my learned friend on IPC::Run3 as a direct replacement to system(), although it can't do some of the more interactive tricks of IPC::Run.

        Morover, IPC::Run3 works on every single platform flawlessly, and so it makes for a very safe dependency. Some of the others do have the odd platform issue.

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://557113]
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others examining the Monastery: (4)
As of 2018-01-21 03:58 GMT
Find Nodes?
    Voting Booth?
    How did you see in the new year?

    Results (227 votes). Check out past polls.