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

Hi, I've been using Perl for 10 days now and I have found the site extrememly useful and friendly. I am attempting to use the command line version of winzip to zip a file. The script works, but when I run it, a press any key to continue prompt appears and I have to press a key before it will do it's work. When I press a key it does what I expect. I think I should use '<', but I'm not sure where to put it. I tried inside the ticks after I invoke winzip and pass the filenames, but I still had to manually hit a key. Here is the code of my script. Thank you very much
my $input = "c:/Backups/UCSRSQL01/sortedREFDATAList.txt"; open(INPUT, $input) ; my $zipfile = <INPUT> ; my $path = "C:/Backups/UCSRSQL01"; $zipcommand = `"c:/program files/winzip/wzzip" $path/refdatabak.zip $p +ath/$zipfile`;

Replies are listed 'Best First'.
Re: Script waiting on 'Press any key to continue'
by Roy Johnson (Monsignor) on Apr 25, 2005 at 16:20 UTC
    I would recommend that you use the Archive::Zip module instead of calling winzip. If you feel daunted by using a module, you could at least use plain ordinary zip rather than winzip.

    But to answer your question, you can try close STDIN before running the command, assuming you don't need to get anything from STDIN elsewhere in your script.


    Caution: Contents may have been coded under pressure.
Re: Script waiting on 'Press any key to continue'
by eibwen (Friar) on Apr 25, 2005 at 16:18 UTC

    First and foremost:

    use strict; use warnings; # or -w

    Additionally, check the return of open (or die "Error: $!";), close INPUT, and verify that wzzip isn't the one waiting for 'press any key'...

    Also, verify that you really want $zipfile = <INPUT> (returns a line from the file -- if this is the first such invocation, the first line). Depending on your implementation, you may want to use something like:

    @zipfiles = <INPUT>; foreach my $zipfile (@zipfiles) { # unzip $zipfile }

Re: Script waiting on 'Press any key to continue'
by felonius (Scribe) on Apr 25, 2005 at 16:20 UTC
    I'm fairly new here myself, but you may want to take a look at the module Archive::Zip. I havn't used it myself but the documentation shows it as being pretty comprehensive.
Re: Script waiting on 'Press any key to continue'
by bofh_of_oz (Hermit) on Apr 25, 2005 at 18:12 UTC
    I would support the earlier advice of the esteemed monks to use Archive::Zip module as it provides a fairly easy and straightforward way to zip files.

    Here is a function that I use in my scripts (it might be not the best way to do it, but it works...)

    sub ZipFile($) { my $fname = @_[0]; my $error = 0; my $zipfile = $fname.'.zip'; #Update filename, add .ZIP at the end my $zip = Archive::Zip -> new(); my $member = $zip->memberNamed( $fname ); if ($member eq undef) #No existing zip file with the file inside { $member = $zip->addFile( $fname ) or $error = 1; #Add file to ZI +P archive push @ERRORS, "Unable to zip $fname: $!\n" if $error; LogError() if $error; } $member -> desiredCompressionLevel( 9 ); my $status = $zip -> overwriteAs($zipfile); push @LOG, "$fname compressed (zipped) successfully\n"; return $zipfile; #Return updated filename }

    The function attempts to create a new .ZIP file, and 'add' a text file into the archive, thereby doing the same thing that you do when using Winzip to compress the file.

    Hope this helps :)

    --------------------------------
    An idea is not responsible for the people who believe in it...

Re: Script waiting on 'Press any key to continue'
by tame1 (Pilgrim) on Apr 25, 2005 at 19:19 UTC
    Although it's a little on the heavy side for what you seem to want to do, Perl's Expect module is very very usefull for automating things that expect input in one form or another.


    What does this little button do . .<Click>; "USER HAS SIGNED OFF FOR THE DAY"