in reply to Need suggestion for selecting IPC::Open3 or backticks

G'day techman2006,

Take a look at "perlop: Quote-Like Operators". Under qx/STRING/ (aka `STRING`), you'll find information on how to check for problems with whatever command you're running.

Also, in "perlvar: Error Variables", under $CHILD_ERROR (aka $?), you'll see how to get the status of such commands.

For running a simple tar command, IPC::Open3 doesn't seem appropriate; however, if you have more complex usage, an explanation of this would lead to a more informed answer.

-- Ken

Replies are listed 'Best First'.
Re^2: Need suggestion for selecting IPC::Open3 or backticks
by techman2006 (Beadle) on Nov 12, 2013 at 18:29 UTC

    G'day Ken,

    Thanks for the references. Let me try to explain the problem on which I am working.

    I need to scan a set of directory and based on certain criteria I may need to perform a tar operation. Once the operation is successful I need to update some entries in DB( a SQLite DB).

    Now the issue is say an user use Ctrl-C to abort the program. As it may come while DB operations going on it will result into a inconsistent state of DB (which need to be avoided). As if the program run again the flow will be decided based on the entries in DB.

    So there are two ways to handle such case

    1. Catch all such signals and let the program run

    2. Catch such signals and handle the condition gracefully.

    So I am thinking to take approach 2 for the same. So I was thinking how to achieve the same. Any example with this reference will be great help.

    Hope this will help.

      "perlipc: Signals" explains how to trap and handle signals.

      There's quite a few examples, including $SIG{INT} which is what you want for Ctrl-C.

      Make sure you read down to the caveat: "Be careful: qx(), system(), and some modules for calling external commands ..." - this also has example code.

      -- Ken