Perl scripts and Pkunzip

How can I write a Perl script that will use PKUNZIP to unzip a specified file ?  Also is it possible to make the script check the error code that PKUNZIP returns and inform me if an error occured while trying to unzip a file ?

I would be grateful for all help offered regarding this.

John Clarke
johnclarkeAsked:
Who is Participating?
 
mjswartConnect With a Mentor Commented:
Try

$returnvalue = system("PKUNZIP", "myfile.zip");
0
 
powerinternetCommented:
Hi,

Assuming you have "unzip" or "pkunzip" (depending on what system you are on)
then its dead easy...

$return=`pkunzip myfile.zip`;
if ($?) {
    print "Erorr occured unzipping\n";
}

You can also use the "system" call from within perl.

the $return is populated with any output from the "pkunzip"... however, ouput can go to STDERR so, you cannot determine success via this method.

To be 100% sure you should check the special variable $? which is set after a system call with the commands result code.  The above code illustrates this.

-Mark
0
All Courses

From novice to tech pro — start learning today.