这个 zip 命令在 perl 中是如何使用的?
我在 perl 中找到了这段代码,
system("zip $ZIP_DEBUG -r -9 itvlib.zip $include $exclude");
但是我不明白它是如何工作的。我的意思是 system() 用于触发“系统”命令,对吗?那么这里使用的“zip”命令是“系统”命令吗? 但我尝试在命令提示符下触发以下命令;
zip $ZIP_DEBUG -r -9 itvlib.zip arg1 arg2
没用! 它给出了以下错误:
'zip' is not recognized as an internal or external command,
operable program or batch file.
嗯,这不应该发生,因为该命令似乎使用“zip”作为系统命令。所以这使得命令“zip”变得神秘
你能帮我理解这个命令及其所有参数吗?
I found this piece of code in perl
system("zip $ZIP_DEBUG -r -9 itvlib.zip $include $exclude");
However I don't understand how it is working. I mean system() is used to fire 'system' commands right ? So is this 'zip' command used here a 'system' command ?
But I tried firing just the following on the command prompt;
zip $ZIP_DEBUG -r -9 itvlib.zip arg1 arg2
It didn't work !
it gave the following error:
'zip' is not recognized as an internal or external command,
operable program or batch file.
Well this shouldn't have happened, since the command seems to use 'zip' as a system command. So this makes the command 'zip' mysterious
Can you please help me to understand this command with all its parameters?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
它可能不起作用,因为您没有将
$ZIP_DEBUG
等内容替换为等效的真实值。在 Perl 中,它们将在传递给系统
调用之前被变量的值替换。如果在执行系统调用之前打印出这些 Perl 变量(甚至整个命令),您将找到需要使用的实际值。您可以使用以下文字来指导您:
有关
system
如何工作的详细信息,请参阅从命令行 shell(假设您使用的是 Linux 或其兄弟)。相反,如果您使用的是不同的操作系统(例如 Windows),则必须弄清楚如何获取 zip 选项。这可能很简单,就像
zip -h
的zip -?
一样,但不能保证它会起作用。如果它与 Linux 下的 Info-ZIP
zip
相同(如果您有-9
和-r
选项并且您的exclude
变量以-x
开头),然后zip -h
将为您提供基本帮助,zip -h2
将为您提供基本帮助给你更多。It's probably not working since you're not replacing things like
$ZIP_DEBUG
with their equivalent real values. Within Perl, they will be replaced with the values of the variables before being passed to thesystem
call.If you print out those Perl variables (or even the entire command) before you execute that
system
call, you'll find out those real values that you need to use. You can use the following transcript to guide you:For details on how
system
works, see here. For details on whatzip
needs to function, you should just be able to run:from a command line shell (assuming you're on Linux or its brethren). If, instead, you're on a different operating system (like Windows), you'll have to figure out how to get the zip options out. This may well be as simple as
zip -?
ofzip -h
but there's no guarantee that will work.If it's the same as the Info-ZIP
zip
under Linux (and it may be if you have the-9
and-r
options and yourexclude
variable starts with-x
), thenzip -h
will get you basic help andzip -h2
will give you a lot more.正在路径上的某处运行名为
zip
的程序(可能是zip.exe
)。$ZIP_DEBUG
、$include
和$exclude
是在命令运行之前插入到命令行中的 Perl 变量。如果
system
调用在 Perl 脚本中有效,但zip -?
给出'zip' 未被识别为内部或外部命令、可操作程序或批处理file
错误,那么 Perl 脚本的 PATH 必须与命令提示符中的 PATH 不同。或者,当 Perl 执行system
命令时,当前目录中可能存在zip
命令。 (在 Windows 中,当前目录是 PATH 的隐式成员。)要查看 Perl 脚本的 PATH,您可以在前面添加
print "$ENV{PATH}\n";
系统命令。要在命令提示符中查看 PATH 是什么,请键入PATH
。is running a program named
zip
(probablyzip.exe
) somewhere on the path.$ZIP_DEBUG
,$include
, and$exclude
are Perl variables that are interpolated into the command line before the command is run.If the
system
call works in the Perl script, butzip -?
gives the'zip' is not recognized as an internal or external command, operable program or batch file
error, then the PATH of the Perl script must be different than the PATH in your command prompt. Or, there might be azip
command in the current directory when Perl executes thesystem
command. (In Windows, the current directory is an implicit member of your PATH.)To see what the PATH is for the Perl script, you can add a
print "$ENV{PATH}\n";
before the system command. To see what the PATH is in your command prompt, typePATH
.是的,
zip
是一个系统命令。变量$ZIP_DEBUG
等是在启动zip
之前插入到命令中的 Perl 变量。要调试实际调用是什么,请尝试添加:
有关
的详细信息,请参阅 perldoc系统。
Yes,
zip
is a system command. The variables$ZIP_DEBUG
and such are perl variables that are interpolated to the command before launchingzip
.To debug what the actual call is, try adding:
See perldoc for details on
system
.