man rar...
-m<0..5>
Set compression level (0-store...3-default...5-best). By default
rar uses -m3 method (Normal compression).
...
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38
# globale Definition der Kommando-Pfade my %cmd = ( rar => '/path/to/rar', ); # globale Definition von Optionen pro Kommando, die immer gelten sollen my %opts = ( rar => [ 'a', '-m0' ], ); # .... sub rar { my $archive = shift; my @files = @_; if ( !exists $cmd{rar} ) { die "No path to rar is defined in \%cmd\n"; } elsif ( not -x $cmd{rar} ) { die "$cmd{rar} is not executable\n"; } my @cmd = ( $cmd{rar}, # wenn globale Optionen definiert sind, nutze sie ( $opts{rar} ? @{$opts{rar}} : () ), $archive, @files ); return system(@cmd); } # ... rar( $archive, @files ) or die "rar failed for '$archive' : $!\n";
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
use Archive::Rar::Passthrough; my $rar = Archive::Rar::Passthrough->new(); if (not $rar) { print "Could not find your 'rar' command'.\n"; } my $errorcode = $rar->run( command => 'a', switches => ['-m0'], archive => 'my.rar', filelist_files => [ 'test.txt' ], ); if ($errorcode) { print "There was an error running 'rar': " . $rar->explain_error($retval) . "\n"; my $output = $rar->get_stdout(); my $errors = $rar->get_stderr(); print "The 'rar' command said (if anything):\n" . $output . "\nAnd spammed on STDERR:\n" . $errors . "\n"; }
command => 'a','cw [comment]' ,
1
2
3
4
5
6
# 1. Archiv erstellen
rar a -m0 archive.rar file1.txt file2.txt
# 2. Kommentar ans Archiv hinzufuegen
echo "mein Archiv Kommentar" | rar c archive.rar
# 3. Kommentar kontrollieren
rar cw archive.rar
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
#! /usr/bin/env perl use strict; use warnings; use Archive::Rar::Passthrough; my $rar = Archive::Rar::Passthrough->new(); my $rc = $rar->run( 'command' => 'a', 'switches' => [ '-m0' ], archive => 'my.rar', files => [ glob("*.txt") ], ); # Fehlerbehandlung print "Please enter the archive comment now (<CTRL>+D ends comment):\n"; $rc = $rar->run( 'command' => 'c', archive => 'my.rar', ); # Fehlerbehandlung
1
2
3
4
5
6
7
8
$ perl t.pl
Please enter the archive comment now (<CTRL>+D ends comment):
bla
^D
$
$ echo "lese von stdin" | perl t.pl
Please enter the archive comment now (<CTRL>+D ends comment):
$
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
use Archive::Rar::Passthrough; my $rar = Archive::Rar::Passthrough->new(); if (not $rar) { print "Could not find your 'rar' command'.\n"; } $rar->run( command => 'a', switches => ['-m0'], archive => 'my.rar', filelist_files => [ 'test.txt' ], ); $rar->run( command => 'c', archive => 'my.rar', );
KarlaCluftAber es scheint SO nicht zu funktionieren...
1
2
3
4
5
6
7
8
9
10
11
$ rar c my.rar
Processing archive my.rar
Reading comment from stdin
here is my comment<ENTER>
<CTRL+D>
Adding comment to my.rar
Done
$
$ rar cw my.rar
here is my comment
$
1 2 3 4 5
$rar->run( command => 'c', archive => 'my.rar', switches => ['-zcomment.txt'], );