views:

122

answers:

3

Is it possible to call winrar through perl on a windows system, such as

perl -e "rar a -rr10 -s c:\backups\backup.rar @backup.lst"

If so, is there a more efficient way to do this?

I've looked up "perl -e" +winrar on google, however none of the results gave me any answer that was remotely close to what i was looking for. The system Im running this on is a Windows XP system. Im open to doing this in another language like python if its easier, however I am more comfertable with perl.

+1  A: 

To use external applications from your Perl program, use the system builtin.

If you need the output from the command, you can use the backtick (``) or qx operator as discussed in perlop. You can also use pipes as discussed in perlipc.

friedo
Would I still need to set the env like:$ENV{winrar} = "C:\Program Files\WinRAR\"; or can I skip that using system
perlnoob
A: 

One way to execute external commands from a Perl script is to use system:

my $cmd = 'rar a -rr10 -s c:\backups\backup.rar @backup.lst';
if (system $cmd) {
    print "Error: $? for command $cmd"
}
toolic
Thanks, this answer was very clear.
perlnoob
The only problem I have is I have to run it in the winrar directory. Other than that, it works like a charm.
perlnoob
Does it help if you change it to "c:\path\to rar ......"
justintime
@toolic There are at least two bugs in that code. One would have been caught by the use of `warnings`, the other might be slightly harder to see.
Sinan Ünür
Updated to prevent interpolation in string. The OP did not provide sufficient detail for me to know if `@backup` is a variable or a literal string (it looks strange to me either way). Despite the ambiguity, the OP found my fuzzy answer useful enough to accept it. It would be great if others would be as tolerant of fuzzy answers to fuzzy questions.
toolic
+3  A: 

You can access the RAR facilities in Windows using the CPAN module Archive::Rar:

use Archive::Rar;
my $rar = Archive::Rar->new(-archive => $archive_filename);
$rar->Extract();
Ether