Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses
 
PerlMonks  

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

Comment on excuting the tar command
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 Beatnik (Parson) on Apr 25, 2001 at 18:04 UTC
    Personally I kinda like Archive::Tar.

    Greetz
    Beatnik
    ... Quidquid perl dictum sit, altum viditur.
Re: excuting the tar command
by KM (Priest) on Apr 25, 2001 at 18:10 UTC
    Have you looked at the Archive::Tar module?

    Cheers,
    KM

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 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

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://75450]
Approved by root
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others having an uproarious good time at the Monastery: (3)
As of 2014-11-01 11:18 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    For retirement, I am banking on:










    Results (229 votes), past polls