这个 zip 命令在 perl 中是如何使用的?

发布于 2024-12-16 21:47:32 字数 505 浏览 0 评论 0原文

我在 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

可是我不能没有你 2024-12-23 21:47:32

它可能不起作用,因为您没有将 $ZIP_DEBUG 等内容替换为等效的真实值。在 Perl 中,它们将在传递给系统调用之前被变量的值替换。

如果在执行系统调用之前打印出这些 Perl 变量(甚至整个命令),您将找到需要使用的实际值。您可以使用以下文字来指导您:

$ perl -e '
>     $ZIP_DEBUG = "xyzzy";
>     $include = "inc_files";
>     $exclude = "exc_files";
>     print "zip $ZIP_DEBUG -r -9 itvlib.zip $include $exclude";
> '
zip xyzzy -r -9 itvlib.zip inc_files exc_files

有关 system 如何工作的详细信息,请参阅

man zip

从命令行 shell(假设您使用的是 Linux 或其兄弟)。相反,如果您使用的是不同的操作系统(例如 Windows),则必须弄清楚如何获取 zip 选项。这可能很简单,就像 zip -hzip -? 一样,但不能保证它会起作用。

如果它与 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 the system 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:

$ perl -e '
>     $ZIP_DEBUG = "xyzzy";
>     $include = "inc_files";
>     $exclude = "exc_files";
>     print "zip $ZIP_DEBUG -r -9 itvlib.zip $include $exclude";
> '
zip xyzzy -r -9 itvlib.zip inc_files exc_files

For details on how system works, see here. For details on what zip needs to function, you should just be able to run:

man zip

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 -? of zip -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 your exclude variable starts with -x), then zip -h will get you basic help and zip -h2 will give you a lot more.

假装爱人 2024-12-23 21:47:32
system("zip $ZIP_DEBUG -r -9 itvlib.zip $include $exclude");

正在路径上的某处运行名为 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

system("zip $ZIP_DEBUG -r -9 itvlib.zip $include $exclude");

is running a program named zip (probably zip.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, but zip -? 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 a zip command in the current directory when Perl executes the system 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, type PATH.

我的黑色迷你裙 2024-12-23 21:47:32

是的,zip 是一个系统命令。变量 $ZIP_DEBUG 等是在启动 zip 之前插入到命令中的 Perl 变量。

要调试实际调用是什么,请尝试添加:

print("zip $ZIP_DEBUG -r -9 itvlib.zip $include $exclude\n");

有关 的详细信息,请参阅 perldoc系统。

Yes, zip is a system command. The variables $ZIP_DEBUG and such are perl variables that are interpolated to the command before launching zip.

To debug what the actual call is, try adding:

print("zip $ZIP_DEBUG -r -9 itvlib.zip $include $exclude\n");

See perldoc for details on system.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文