Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?

excuting the tar command

by Anonymous Monk
on Apr 25, 2001 at 17:58 UTC ( #75450=perlquestion: print w/replies, xml ) Need Help??
Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

I am trying to automate some of my backups. I wrote a small perl script to tar directories. Some of the directories are located on a windows partition. The following command works from the command line in Linux but not in the script.

tar cvf /backup/desktop.tar /drive-c/windows/Program\ Files/Desktop.

In the perl script the space between Program and Files has tar thinking it is two diffrent directories and it errors out. I have tried several diffrent variables but nothing seems to work. Thanks, David

Replies are listed 'Best First'.
Re: excuting the tar command
by Beatnik (Parson) on Apr 25, 2001 at 18:04 UTC
    Personally I kinda like Archive::Tar.

    ... Quidquid perl dictum sit, altum viditur.
Re: excuting the tar command
by merlyn (Sage) on Apr 25, 2001 at 19:16 UTC
    system "tar", "cvf", "/backup/desktop.tar", "/drive-c/windows/Program +Files/Desktop";
    The multi-arg version of system means that whitespace is just data, and parameters are passed one-for-one into the child program's equivalent of @ARGV.

    -- Randal L. Schwartz, Perl hacker

Re: excuting the tar command
by turnstep (Parson) on Apr 25, 2001 at 18:01 UTC
    Quote the directory with the space:
    my $tarcom = qq{tar cvf /backup/desktop.tar "/drive-c/windows/Program Files/Desktop +"};
Re: excuting the tar command
by alfie (Pilgrim) on Apr 25, 2001 at 18:11 UTC
    Do you call the command in the script using back-ticks or system? Furthermore, have you tried to escape the \? It might be that you need to do that because the \ might just escape the space, perl converts it into a plain space and hands that over to the shell. So make sure that the \ is handed to the shell, by either using single quotes in the system call or escaping the \ (so using Program\\ Files). Maybe you might want to use the Archive::Tar module instead to do it directly from perl.
    use signature; signature(" So long\nAlfie");
      Thanks for the help. I will try your suggestion and check into the Archive::Tar module. David
      I was kinda quick on the reply and did not answer your questions. I use the back-ticks and I did not escape the \. I will try your suggestions and let you know the results. Thanks again, David
Re: excuting the tar command
by KM (Priest) on Apr 25, 2001 at 18:10 UTC
    Have you looked at the Archive::Tar module?


Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://75450]
Approved by root
[erix]: (but then there's always a next (im)possible goal)
Corion avoids running by starting on time
[choroba]: my phone showed me 1 hour 10 km which was my goal, it changed a bit after uploading to the website
[erix]: choroba I believe you ;)
[1nickt]: Corion I assume you are talking about Retry? Attempt doesn;t offer callbacks and has a much simpler interface. (Also written by someone I trust...)

How do I use this? | Other CB clients
Other Users?
Others chilling in the Monastery: (8)
As of 2017-05-24 12:56 GMT
Find Nodes?
    Voting Booth?