如何使用 7z 测试?

发布于 2025-01-12 09:03:51 字数 501 浏览 3 评论 0原文

文件的目录已定义。

我想使用 7z 的“test”命令获取“test”值。

foreach $str0 (glob "*.zip"){
    my $test = system( "7z t -y $str0");
    print $test;
}

如何获得“7z 测试”值?


编辑:

您的意思是使用 qx 而不是 System 吗?

你的意思是对的吗?

foreach $str0 (glob "*.zip"){
    my $test = qx/7z t -y $str0/;
    print $test;
}

或者

foreach $str0 (glob "*.zip"){
    my $test = `7z t -y $str0`;
    print $test;
}

我都尝试了,但无法获得“测试值”。

The directory of the file is defined.

I want to get the 'test' value using the 'test' command of 7z.

foreach $str0 (glob "*.zip"){
    my $test = system( "7z t -y $str0");
    print $test;
}

How can I get the '7z test' value?


Edit:

Do you mean to use qx instead of System?

Is it right that you meant it?

foreach $str0 (glob "*.zip"){
    my $test = qx/7z t -y $str0/;
    print $test;
}

or

foreach $str0 (glob "*.zip"){
    my $test = `7z t -y $str0`;
    print $test;
}

I tried both, but I can't get the 'test value'.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(1

挽容 2025-01-19 09:03:51

在 Perl 中至少有三种方法可以做到这一点: qx 和反引号方式基本上是相同的,除了使用 qx 时,您可以选择使用什么分隔符来开始/结束字符串。使用 ' 作为分隔符可防止变量插值。

第三种方法是使用 open 打开 7zip 的管道。

#with qx
my $test = qx/7z t -y $str0/;

#with backticks
my $test = `7z t -y $str0`;

#with open
open my $pipe, '-|', '7z', 't', '-y', $str0;
my $test = join "\n", readline $pipe;
close $pipe;

There are at least three ways to do this in Perl; the qx and backticks ways are basically the same thing, except with qx you have a choice of what delimiter to use to start/end the string. Using ' as the delimiter prevents variable interpolation.

The third way is using open to open a pipe to 7zip.

#with qx
my $test = qx/7z t -y $str0/;

#with backticks
my $test = `7z t -y $str0`;

#with open
open my $pipe, '-|', '7z', 't', '-y', $str0;
my $test = join "\n", readline $pipe;
close $pipe;
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文