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

Re: tar, system() & pipes?

by ikegami (Patriarch)
on Jul 17, 2007 at 20:29 UTC ( #627120=note: print w/replies, xml ) Need Help??

in reply to tar, system() & pipes?

The > /tmp/file is a *shell* directive, but the shell is not invoked when you use system LIST instead of system EXPR. You're passing > and /tmp/file as arguments to tar, and tar doesn't know what to do with them.

Replies are listed 'Best First'.
Re^2: tar, system() & pipes?
by Anonymous Monk on Jul 17, 2007 at 20:35 UTC

    Thank you for your reply.

    So there isn't a way to spawn piped commands from within a Perl script?

      I think the following is safe on unix platforms:

      my $q_archive = quotemeta($ARGV[0]); my $q_filename = quotemeta($filename); system("tar $args $q_archive > $q_filename")

      It can also be written as

      system("tar $args \Q$ARGV[0]\E > \Q$filename\E")

      quotemeta (called directly or via \Q..\E) will backslash-escape any non-word characters, so the file names can safely contain symbols and spaces.

        Thank you! Use of quotemeta appears to work.

        Why is this needed?

      If the intention is to read the output file back into your program once tar is finished, you could bypass the filesystem by using a piped-open:

      (See the docs for perlfuncopen and perlopentut)

      # ..................v open TAR, "tar .... |" or die ...; while( <TAR> { ## do stuff with the tar output }

      ## do stuff with the tar output could be as simple as print FILE $_;.

      See also IO::Pipe.

      Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
      "Science is about questioning the status quo. Questioning authority".
      In the absence of evidence, opinion is indistinguishable from prejudice.

Log In?

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://627120]
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others pondering the Monastery: (3)
As of 2023-03-26 02:32 GMT
Find Nodes?
    Voting Booth?
    Which type of climate do you prefer to live in?

    Results (63 votes). Check out past polls.