Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling
 
PerlMonks  

7zip a folder

by ytjPerl (Scribe)
on Oct 30, 2017 at 18:15 UTC ( [id://1202353]=perlquestion: print w/replies, xml ) Need Help??

ytjPerl has asked for the wisdom of the Perl Monks concerning the following question:

Hi folk, I am looking to 7zip a folder which contains log files. it keeps telling me can't find string terminator '''' anywhere before EOF My code as below:
my $log = "C:/Users/tt/Documents/Traning/Archive/log.txt"; my $base = 'C:/Users/tt/Documents/Traning/Archive'; my $archive = "$base/$date.7z"; print $log capture_merged{system ('C:/Program Files/7-Zip/7z.exe', ' e + ', $archive, '-r, $file' , "\n\n\" )};
Please correct me, thanks in advance

Replies are listed 'Best First'.
Re: 7zip a folder
by toolic (Bishop) on Oct 30, 2017 at 18:19 UTC
Re: 7zip a folder
by choroba (Cardinal) on Oct 30, 2017 at 18:21 UTC
    "\n\n\" ^
    The last backslash quotes the following double quote, so it's included in the double quoted string, but the ending double quote is missing.

    ($q=q:Sq=~/;[c](.)(.)/;chr(-||-|5+lengthSq)`"S|oS2"`map{chr |+ord }map{substrSq`S_+|`|}3E|-|`7**2-3:)=~y+S|`+$1,++print+eval$q,q,a,
Re: 7zip a folder
by Marshall (Canon) on Oct 30, 2017 at 19:44 UTC
    Take a look at Perl system function.
    I don't understand capture_merged{} in the context of your code.
    What is "capture_merged"?.
    I don't see an open to the file handle $log.

    When debugging an error, simplify, simplify. See how you get on with:

    my @args = ("command", "arg1", "arg2"); system(@args) == 0 or die "system @args failed: $?";
    Single quotes, ' vs double quotes, " matter.
Re: 7zip a folder
by thanos1983 (Parson) on Oct 31, 2017 at 10:28 UTC

    Hello ytjPerl,

    It seems that the fellow Monks have tried to assist you. Since you have not updated your question if you have resolved the issue/problem I will just add some minor notes, hopping that they will assist you.

    There have been a few similar questions to yours, like Perl and 7zip and backticks and Caturing 7zip output with Perl. I also found a relevant module Archive::SevenZip, which should minimize the errors.

    Read the questions, try to apply the module and let us know if it worked for you.

    Hope this helps, BR.

    Seeking for Perl wisdom...on the process of learning...not there...yet!

      I saw this command

      Perl> open PIPE, '-|', '"\Program Files\7-Zip\7z.exe" e -so e:\UnxUtil +sSrc.zip 2>&1 1>nul' or die $@;;

      which can extract zip file.

      But I still do not know what is the syntax for compress folder. I move all the files into a folder then compress it.

        I'd suggest first reading the 7-zip help to learn how to use it's command line interface. You'll need to understand how to run the command outside of Perl before you can incorporate that command inside your Perl code.

        I believe that the general syntax that you're looking for is:

        "C:\Program Files\7-Zzip\7z.exe" a -tzip my_archive.zip C:\my_data\ -r

        However, putting that into your Perl code and trying to capture the output (STDOUT and/or STDERR) may be a challenge. I apologize for not being able to describe this using correct terminology. The 7z.exe is at times reusing lines in STDOUT to show progress. I could be wrong, but I think that behavior will causes challenges when trying to caputure output messages from the 7z.exe utility.

        I second dasgar's answer, especially the first paragraph. That said, I have compressed things using something like the following, which would compress all .txt files in current and subdirs into target.zip:
        ... use Data::Dumper; ... my @cmd = ( 'c:\Program Files\7-Zip\7z.exe', 'a', '-mx9', '-r', 'target.zip', '*.txt', ); print 'about to execute: ', Dumper \@cmd; system @cmd;
        The 7zip man page is not on their home page, but over there you can have a glance.
Re: 7zip a folder
by ytjPerl (Scribe) on Oct 30, 2017 at 19:04 UTC
    I fixed that. No syntax error. but I do not get the result I want. my folder is not zipped.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://1202353]
Approved by toolic
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others chanting in the Monastery: (2)
As of 2024-04-25 06:44 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found