I am bit confuse to select out of IPC::Open3 or back ticks for running tar command (as need to archive a set of files). But also need to make sure that any abort operation should be avoided as once the tar operation is completed I need to perform some DB operations.
Hi, I'm not completely sure of what you are doing, but if you need to watch the tar command running, to check for an abort situation, I will point out 1 significant difference between backticks and IPC::Open3. Backticks will stop processing of your main script until the backtick completes, necessitating watching signals and return codes. Whereas IPC::Open3 will allow you to use select or IO::Select to watch the returns coming in, and even separate the stdout and stderr of the command.
Just to demonstrate this capability of IPC::Open3, look at this:
#!/usr/bin/perl
use warnings;
use strict;
use IPC::Open3;
use IO::Select;
my $pid = open3(\*WRITE, \*READ,\*ERROR,"/bin/bash");
my $sel = new IO::Select();
$sel->add(\*READ);
$sel->add(\*ERROR);
my($error,$answer)=('','');
while(1){
print "Enter command\n";
chomp(my $query = <STDIN>);
#send query to bash
print WRITE "$query\n";
foreach my $h ($sel->can_read)
{
my $buf = '';
if ($h eq \*ERROR)
{
sysread(ERROR,$buf,4096);
if($buf){print "ERROR-> $buf\n"}
}
else
{
sysread(READ,$buf,4096);
if($buf){print "$query = $buf\n"}
}
}
}
waitpid($pid, 1);
# It is important to waitpid on your child process,
# otherwise zombies could be created.
|