Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:
I'm needed to do further processing on the contents of a tar file. Manually, I'm simply issue:
...to create a list of directories & files, but doing this programmatically within a Perl script is giving me problems.$ tar txf syssrc.tgz > /tmp/file
If I don't redirect, the following code works:
I get the following warning:#!/usr/bin/perl use strict; use warnings; use Readonly; Readonly my $filename => '/tmp/contents'; my $args = 'tf'; eval { die 'incorrect #command-line arguments' unless @ARGV == 1; # add switches based on filetype if ($ARGV[0] =~ /tgz$/) { $args .= 'z'; } # dump tar contents to file if (system('tar', $args, $ARGV[0]) != 0) { if ($? == -1) { die "failed to execute '$!'"; } elsif ($? & 127) { die sprintf 'child process died with signal %d %s', ($? & 127), (($? & 128) ? 'with coredump' : ''); } else { printf "child process exit value:\t%d\n", ($? >> 8); } } }; if ($@) { $@ =~ s/at $0 line \d+\.$//; print "syntax:\t$0 <filename>\n"; print "error:\t$@\n"; } ..but if I change the <b>system()</b> call to: <code> if (system('tar', $args, $ARGV[0], '>', $filename) != 0) {
...and /tmp/file is not created.tar: WARNING! These patterns were not matched: > /tmp/contents child process exit value: 1
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: tar, system() & pipes?
by philcrow (Priest) on Jul 17, 2007 at 20:29 UTC | |
Re: tar, system() & pipes?
by ikegami (Patriarch) on Jul 17, 2007 at 20:29 UTC | |
by Anonymous Monk on Jul 17, 2007 at 20:35 UTC | |
by ikegami (Patriarch) on Jul 17, 2007 at 20:38 UTC | |
by Anonymous Monk on Jul 17, 2007 at 20:55 UTC | |
by Argel (Prior) on Jul 17, 2007 at 22:11 UTC | |
by BrowserUk (Patriarch) on Jul 17, 2007 at 20:46 UTC |
Back to
Seekers of Perl Wisdom