简体   繁体   中英

How do you use the 7z 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'.

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;

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM