Skip to main content  
        iSeries home   |   Easy400     |   CGIDEV2     |   MMAIL  
Freeware
 
 
 
About it
Prerequisites
Installation
Examples
Programming
Execution environment
Simple commands
 Download
 
 

 
ZIP & UNZIP on System i
Run them on System i, manually or through programs
by Giovanni B. Perotti (Italy)

1-About it

This small utility installs commands ZIP and UNZIP on your System i.
Once installed, commands zip and unzip can be run:

  • in an i5/OS PASE interactive terminal session (started by command CALL QP2TERM)
  • in a QSHELL interactive session (started by command STRQSH)
  • from a program issuing command
    STRQSH CMD(command_to_be_executed)

Note 1 - The original information about installing these commands can be found in the IBM System i Redbook IBM HTTP Server (powered by Apache), APPENDIX C: Bringing Zip and Unzip to i5/OS PASE and QShell Environments by Brian Smith.
This utility, however, makes the installation much easier.

Note 2 - Check out the updates to this tool by pressing this link.
To know the release date of this tool on your Systemi, enter command zip/released.

2-Prerequisites

  • OS/400 release V5R2 or subsequent

3-Installation

  • Download file zip.zip from the Easy400 download page and unzip it.
  • Follow the Readme.txt instructions to upload and to restore library ZIP.
  • On the iSeries run the following procedure:
    STRREXPRC SRCMBR(INSTALL) SRCFILE(ZIP/QREXSRC)
    It does the following:
    • Restores directory /home/zip
    • copies commands ZIP and UNZIP to directory /QOpenSys/usr/bin for use of i5/OS PASE
    • copies commands ZIP and UNZIP to directory /usr/bin for use of QSHELL

4-Examples of commands

  1. Command ZIP
    • zip /zip/test/x.zip /zip/test/a.txt /zip/test/b.txt
      this command compresses files /zip/test/a.txt and /zip/test/b.txt into file /zip/test/x.zip
  2. Command UNZIP
    • unzip /zip/test/x.zip
      this command extracts files /zip/test/a.txt and /zip/test/b.txt,
      but would prompt if a file already exists.
      Notes:
      1. The target directory for the extracted files is the current directory, usually /home/user_profile_name
      2. One may change the current directory (BEFORE STRQSH) with command chgcurdir.
      3. The original file directories are maintained.
    • unzip -o /zip/test/x.zip
      this command extracts files /zip/test/a.txt and /zip/test/b.txt
      Note:
      1. Modifier -o allows to overwrite existing files without prompting for an user decision
    • unzip -n /zip/test/x.zip
      this command extracts files /zip/test/a.txt and /zip/test/b.txt
      Note:
      1. Modifier -n does not overwrite existing files and does not prompt for an user decision
    • unzip -j /zip/test/x.zip
      this command extracts files a.txt and b.txt
      Note:
      1. Modifier -j ignores the directories of the original files
    • unzip /zip/test/x.zip -d /tmp
      this command extracts files /tmp/test/a.txt and /tmp/test/b.txt.
      Note:
      1. Option -d target_directory allows to specify a target directory
    • unzip -P bigblock /zip/test/crypted.zip -d /tmp
      this command unzips crypted file /zip/test/crypted.zip by providing the password "bigblock".

    • My favorite UNZIP format:
      unzip -oj /zip/test/x.zip -d /tmp

5-Running commands from a program

  1. CLLE program
                  PGM
     /*Perform the unzip of file /zip/test/x.zip                       */
     /*           - /zip/test/x.zip                                    */
     /* containing the deflated files:                                 */
     /*           - /test/a.txt                                        */
     /*           - /test/b.txt                                        */
     /*The following files will be inflated:                           */
     /*           - /tmp/a.txt                                         */
     /*           - /tmp/b.txt                                         */
                  STRQSH     CMD('unzip -oj /zip/test/x.zip -d /tmp')
     /*Back to caller                                                  */
                  RETURN
                  ENDPGM
  2. RPGLE program
    D DoCmd           pr            10i 0                                
    D  cmd                        2000    const varying options(*varsize)
    D rc              s             10i 0                                
     *===================================                                
                                                                         
     /free                                                                     
       //Perform the unzip of file /zip/test/x.zip                     
       //           - /zip/test/x.zip                                  
       // containing the deflated files:                            
       //           - /test/a.txt                                  
       //           - /test/b.txt                                  
       //The following files will be inflated:                     
       //           - /tmp/a.txt                                   
       //           - /tmp/b.txt                                   
         rc=docmd('STRQSH CMD(''unzip -oj /zip/test/x.zip -d /tmp'')');
                                                                         
        //back to caller                                                 
          return;                                                        
     /end-free
                                                                         
     *===================================                                
     * docmd local subprocedure                                          
     * Executes a CL command                                             
     * Returns 0 if executed without error; otherwise 1.                 
    Pdocmd            b                                                  
    D docmd           pi            10i 0                                
    D   cmd                       2000    const varying options(*varsize)
                                                                         
    D qcmdexc         pr                  extpgm('QCMDEXC')              
    D  theCmd                     2000    const                          
    D  theCmdLen                    15p 5 const                          
                                                                         
     /free                                                               
       monitor;                                                          
         qcmdexc(%subst(cmd:1:%len(cmd)):%len(cmd));                     
       on-error;                                                         
         return 1;                                                       
       endmon;                                                           
       return 0;       
     /end-free         
                       
    Pdocmd            e

6-Execution environment

When a ZIP or UNZIP command is executed from a program running in interactive mode, the actions taken are displayed in the QSHELL terminal session:
Figure 1- Interactive mode

When a ZIP or UNZIP command is executed from a program running batch mode, the actions taken are printed in a job spool file named QPRINT:
Figure 2- Batch mode

If a program must run an UNZIP command and find out the names of the inflated files, it should operate as follow:

  1. submit a batch job that runs command
    STRQSH CMD('unzip ...')
  2. convert the spool file QPRINT from that job (see Figure 2) to a database file
  3. read this database file to retrieve the names of the inflated files.

7-Simple commands

In order to make developers life easier, two simple standard commands are available: ZIP/ZIP and ZIP/UNZIP.
These commands submit a batch job which runs the appropriate
STRQSH CMD('...')
command.
The result from a command can be displayed by specifying parameter DSP(*YES).

Figure 3- Command ZIP/ZIP
Up to 50 stream files can be zipped.

Figure 4- Command ZIP/UNZIP