On 2/24/06, Irfan J Sayed <[EMAIL PROTECTED]> wrote:
> Hi All,
>
> I need to execute unix tar command thru perl file
> can somebody helps me out in this regard
>
> Regards
> Irfan Sayed
>

You might look at Tar
(http://search.cpan.org/~cdybed/Tar-0.04/Tar.pm), Archive::Tar
(http://search.cpan.org/~kane/Archive-Tar-1.28/lib/Archive/Tar.pm),
and Archive::TarGzip
(http://search.cpan.org/~softdia/Archive-TarGzip-0.03/lib/Archive/TarGzip.pm)
if you need to access the tar files programmaticly.  If you just want
to use the tar executable on your system then you can use system, the
backquote operator (AKA qx()), or a combination of fork and exec.

Assuming you do not need anything but a return value you can say

system("tar cfz foo.tgz /foo/*");

If you want to capture the stdout you can say

my @lines = `tar cvfz foo.tgz /foo/*`;

or

my @lines = qx(tar cvfz foo.tgz /foo/*);

If you need it to run concurrently with the Perl script you can say

$SIG{CHLD} = 'autoreap';

my $fork = fork();
die "could not fork:$!" unless defined $fork;
if ($fork) { #parent code
    print "kicked off a child whose pid is $fork\n";
} else {
    exec('tar', 'cvfz', '/foo/*');
}

I would suggest reading up on system, fork, exec, and the qx()
operator before doing anything.

perldoc -f system
perldoc -f fork
perldoc -f exec
perldoc perlop

or

http://perldoc.perl.org/functions/system.html
http://perldoc.perl.org/functions/fork.html
http://perldoc.perl.org/functions/exec.html
http://perldoc.perl.org/perlop.html

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>


Reply via email to