我如何对 tar 文件进行系统调用(以及排除标记)?使用 Perl 工作
这是系统调用,我现在在 perl 中对文件进行 tar
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
现在我想使用排除标记排除一些文件,这不会排除文件
system("${tarexe} -pcvf $tarname $includepath --exclude $excludepath")
$excludepath -> ./input/myMockPacketName/my3
当我在命令行中运行它时,相同的语句
${tarexe} -pcvf $tarname $includepath --exclude $excludepath
不起作用。
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我不知道为什么你的
--exclude
不起作用。但当我看到正在使用的系统
时,我会给你我最喜欢的perl建议。不要
当然,有时它们是必要的,但首先检查是否有 CPAN 模块来完成这项工作。在这种情况下,我建议 Archive::TarGzip 通常我会使用 Archive::Tar 但我找不到
--exclude
功能 < em>(我只是快速浏览了一下,所以它可能在那里)I haven't a clue to why your
--exclude
isn't working. But I'll give you my favourite perl advice when I see asystem
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)不是问题的直接答案,而是一个可能帮助您确定将来出现此类问题的提示:
而不是编写
类似的内容,
然后您可以将生成的输出剪切并粘贴到新的终端窗口中。或者您可能会发现生成的命令不是您想象的那样。
免责声明 - 我同意大多数回答这个问题的人的观点,即使用 Perl Tar 模块会更好,但接受这样做可能有原因
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
do something like
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
@superstar -
要回答你的具体问题, --exclude 可能应该是“./input/myMockPacketName/my3/*”,而不是我记得的 GNU tar 中的“./input/myMockPacketName/my3”。另外,包含的文件名应该在 --exclude stuff 之后;应该正确引用
但是
为什么要求告诉你如何做而不是做什么?
除非它是家庭作业(在这种情况下,请提前说明)
...或者这些是某些公司通用架构团队的要求(在这种情况下,应该礼貌地教育他们,行业标准最佳实践是在任何时候都使用 Perl 的本机库而不是系统调用)可能,除非有明确的理由不这样做)...
在除这两种情况之外的所有其他情况下,您应该决定使用什么方法来实现。
@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.