views:

158

answers:

4

This is the system call, i am making right now in perl to tar the files

system("${tarexe} -pcvf $tarname $includepath") which works fine.

$tarexe -> location of my tar.exe file
$tarname -> myMock.tar
$includepath -> ./input/myMockPacketName ./input/myPacket/my2/*.wav ./input/myPacket/my3 ./input/myPacket/in.html 

Now i want to exclude some files using exclude tag, which doesnot exclude the files

system("${tarexe} -pcvf $tarname $includepath --exclude $excludepath")

$excludepath -> ./input/myMockPacketName/my3

The same stament

${tarexe} -pcvf $tarname $includepath --exclude $excludepath  

doesnot work when i run it in the command line.

+2  A: 

I haven't a clue to why your --exclude isn't working. But I'll give you my favourite perl advice when I see a system in use.

Don't

Of course sometimes they are necessary but check first if there is a CPAN module to do the job instead. In this case I suggest Archive::TarGzip normally I would use Archive::Tar but I could not find --exclude functionality (I only had a quick look so it may be there)

Nifle
Thank you for responding to me. I had --exclude tag working when i type the same command in command line. But it doesnot work when i call the same thing from the system call in perl. (I need to make a system call here, because i need to use my tar.exe, according to the requirements).
superstar
+1  A: 

@superstar -

To asnwer your specific question, --exclude should probably be "./input/myMockPacketName/my3/*" instead of "./input/myMockPacketName/my3" from what I recall of GNU tar. Also, included file names are supposed to go after --exclude stuff; which should be quoted properly

BUT

Why are the requirements telling you HOW to do stuff as opposed to WHAT to do?

Unless it's homework (in which case please be upfront about it)

... or those are requirements from some company's generic architecture team (in which case they should be politely educated that industry standard best practices are to use Perl's native libraries over system calls whenever possible unless there's a clear reason to do otherwise) ...

in every other but those 2 cases you should decide on what method to use for implementation.

DVK
I tried this as well -> "./input/myMockPacketName/my3/*"but it doesnt work
superstar
Did you try to switch exclude and include places?
DVK
Also, did you try to redirect output/error into a file and seeing what gets printed?
DVK
@DVK: i tried switching places of include and exclude places(in vain).I do not think i am getting an error, the command tars the included paths well, without excluding the excluded paths. is this what you meant? if not, can you be more elaborative. thanks!
superstar
I meant that there may have been some *warning* in the output from tar that didn't halt the tarring yet complained somehow about some issue with excludes.
DVK
Also, could you please try putting in ABSOLUTE path for excludes just to eliminate relative path as a possible culprit? It's unlikely but let's limit the # of moving pieces
DVK
@DVK there are no warnings or errors and i tried absolute and relative paths(result negative).
superstar
Is there ANY difference in output from the command running via Perl and the command running from the OS?
DVK
@DVK: none at all. It includes the given paths(without excluding the exclude path) by call from Perl and thats it !
superstar
Do me a favor. Create a batch file that calls the tar command. Run that batch file from windows and separately from perl. See if it gets better
DVK
sorry for the confusion!! I was actually using the wrong tar. Now i realised i need to use gnu_tar and when i use this the --exclude doesnot work for commandline as well!!
superstar
i was using an older version of tar...now i have updated it!! It works...
superstar
+2  A: 

Not a direct answer to the question but a hint that might help you pin down problems like this in the future:

Rather than write

system("${tarexe} -pcvf $tarname $includepath --exclude $excludepath")

do something like

my $command = "${tarexe} -pcvf $tarname $includepath --exclude $excludepath"  ;

print "About to run $command\n" ;
system $command ;

You can then cut and paste the output getnerated into a new terminal window. Or you may spot that the command generated isnt what you thought it was.

Disclaimer - I agree with most people that have ansewred this question that using Perl Tar modules would be better, but accept there may be reasons for doing it this way

justintime
Thanks for the wise suggestion. I tried it and the $command is what I expect (the same command i ran in command line) but the output does not exclude the directories. Do you think these commands are machine specific?
superstar
Sounds like the problem is to do with TAR rather than Perl. You could try "tar --help" . You could try with a simpler test case from command line.
justintime
@justintime its the problem with system call from Perl, because the same command excludes the paths(with --exclude) in command line. But now from Perl(system call), it tars the include paths well, but doesnot exclude the excluded paths.
superstar
A: 

I appear to be having the same problem, but in a CGI application that uses /usr/bin/zip.

The zip commandstring below works as expected from the commandline on both Solaris and Mac OS X: the paths are excluded and I get a zip file containing only the files matching *.$fileext. But when I run the same command via Perl system(), the zip file contains empty directories for the full path from host root down to htdocs, with the files in the last directory.

Both the commandline and system() cases send the expected STDOUT to the file $joblog, and nothing shows up in the file $joberrors.

This excludes directories as advertised in man zip:

> /usr/bin/zip -D $zipfile $somepath/*.$fileext 1>$joblog 2>$joberrors

This does not:

$zipcommand = "/usr/bin/zip -D $zipfile $somepath/*.$fileext 1>$joblog 2>$joberrors"; system("$zipcommand");

Ideas?

Robert