2008年6月25日 星期三

Get host name in perl script.

Situation:

Want to get the host name which the perl script running on.

====

Solution:

The macro `hostname` helps us to get host name.
Note that `hostname` is not 'hostname'. You need to use `, the key which also send ~ on keyboard.

i.e.

$host_name = `hostname`;

Get the script location, full name rather than working directory.

Situation:

Want to get the location of the script rather than the working directory.
For example, there is a perl script "C:\ooxx\xxoo\aabb.pl". You want to get the directory "C:\ooxx\xxoo".

====
Solution:

For code,

use Cwd;

$workingDir = getcwd;

If you at "C:" and give the command "C:\ooxx\xxoo\aabb.pl", then the current working directory would be "C:".

To get "C:\ooxxx\xxoo", the location of the script, just use

$theSciptFullName = $0;

at the start of the code. When the script just start, the $0 stores the script's full path, that is "C:\ooxx\xxoo\aabb.pl". You can derive the location of the script from the script's full name.

2008年5月12日 星期一

Using fork() exec() like C, Unix environment in Perl.

Use fork() -> exec() in UNIX in Perl.

In UNIX, the child process who called exec() will use the same process id returning by fork.
However, exec() in perl is not like the exec() in UNIX.

int pid = fork();

if (pid) {
// parent
sleep(...);
kill(pid);
}
else {
// child
exec(.....);
}

In this case, the parent process will kill child process by calling "kill(pid)" in c code executing under UNIX.
But things go different in Perl
The similar code

$pid = fork();

if ($pid) {
sleep(...);
kill 'KILL', $pid;
}
else {
exec(....);
}

Although the parent process can still kill child by using "kill 'KILL', $pid", the process triggered by exec(....) still alive.
Since setpgrp() does not always work, the solution of mine is using module WIn32::Process.

http://www.xav.com/perl/site/lib/Win32/Process.html
(If the link became unavailable, just goole "Perl Win32::Process")

By using Win32::Process to open the process, you can get process id by method GetProcessID().
It seems that there is also a function "Kill" to kill the process.
However, I am not sure whether it works well. Meanwhile, it may not also close all its' child process.
I use

kill 'SIGABRT', $ProcessObj->GetProcessID();

instead.

2008年5月9日 星期五

Helpful tutorial for Perl XML::Parser

This tutorial help me figuring out XML::Parser and using it.

http://www.perlmonks.org/?node_id=62782

Following are part of the contents of this web page.
Let me emphasis that the following contents are copied from
http://www.perlmonks.org/?node_id=62782
========

XML::Parser Tutorial
by OeufMayo
on Mar 07, 2001 at 20:54 UTC ( #62782=perltutorial: print w/ replies, xml )
We all agree that Perl does a really good job when it comes to text extraction, particulary with regular expressions.
The XML is based on text, so one might think that it would be dead easy to take any XML input and have it converted in the way one wants.
Unfortunately, that is wrong. If you think you'll be able to parse a XML file with your own homegrown parser you did overnight, think again, and look at the XML specs closely. It's as complex as the CGI specs, and you'll never want to waste precious time trying to do something that will surely end up wrong anyway. Most of the background discussions on why you have to use CGI.pm instead of your own CGI-parser apply here.

The aim of this tutorial is not to show you how XML should be structured and why you shouldn't parse it by hand but how to use the proper tool to do the right job.
I'll focus on the most basic XML module you can find, XML::Parser. It's written by Larry Wall and Clark Cooper, and I'm sure we can trust the former to make good software (rn and patch are his most famous programs)
Okay, enough talk, let's jump into the module!

This tutorial will only show you the basics of XML parsing, using the easiest (IMHO) methods. Please refer to the perldoc XML::Parser for more detailed info.
I'm aware that there are a lot of XML tools available, but knowing how to use XML::Parser can surely help you a lot when you don't have any other module to work with, and it also helped me to understand how other XML modules worked, since most of them are built on top of XML::Parser.
The example I'll use for this tutorial is the Perlmonks Chatterbox ticker that some of you may have already used. It looks like this:

<CHATTER><INFO site="http://perlmonks.org" sitename="Perl Monks">
Rendered by the Chatterbox XML Ticker</INFO>
<message author="OeufMayo" time="20010228112952">
test</message>
<message author="deprecated" time="20010228113142">
pong</message>
<message author="OeufMayo" time="20010228113153">
/me test again; :)</message>
<message author="OeufMayo" time="20010228113255">
<a href="#">please note the use of HTML
tags</a></message>
</CHATTER>

Thanks to deprecated for his unaware intervention here

( The astute reader will notice that in the CB ticker, a 'user_id' has shown up recently. Since it wasn't there when I took my 'snapshot' of the CB, I'll ignore it, but don't worry the code below won't break at all, precisely because I used a proper parser to handle that for me! )

Let's assume we want to output this file in a readable way (though it'll still be barebone). It doesn't handles links and internal HTML entities. It only gets the CB ticker, parses it and prints it, you have to launch it again to follow the wise meditations and the brilliant rethoric of the other fine monks present at the moment.

1 #!/usr/bin/perl -w
2 use strict;
3 use XML::Parser;
4 use LWP::Simple; # used to fetch the chatterbox ticker
5
6 my $message; # Hashref containing infos on a message
7
8 my $cb_ticker = get("http://perlmonks.org/index.pl?node=chatterbox+
+xml+ticker");
9 # we should really check if it succeeded or not
10
11 my $parser = new XML::Parser ( Handlers => { # Creates our parse
+r object
12 Start => \&hdl_start,
13 End => \&hdl_end,
14 Char => \&hdl_char,
15 Default => \&hdl_def,
16 });
17 $parser->parse($cb_ticker);
18
19 # The Handlers
20 sub hdl_start{
21 my ($p, $elt, %atts) = @_;
22 return unless $elt eq 'message'; # We're only interrested in
+what's said
23 $atts{'_str'} = '';
24 $message = \%atts;
25 }
26
27 sub hdl_end{
28 my ($p, $elt) = @_;
29 format_message($message) if $elt eq 'message' && $message && $
+message->{'_str'} =~ /\S/;
30 }
31
32 sub hdl_char {
33 my ($p, $str) = @_;
34 $message->{'_str'} .= $str;
35 }
36
37 sub hdl_def { } # We just throw everything else
38
39 sub format_message { # Helper sub to nicely format what we got fro
+m the XML
40 my $atts = shift;
41 $atts->{'_str'} =~ s/\n//g;
42
43 my ($y,$m,$d,$h,$n,$s) = $atts->{'time'} =~ m/^(\d{4})(\d{2})(
+\d{2})(\d{2})(\d{2})(\d{2})$/;
44
45 # Handles the /me
46 $atts->{'_str'} = $atts->{'_str'} =~ s/^\/me// ?
47 "$atts->{'author'} $atts->{'_str'}" :
48 "<$atts->{'author'}>: $atts->{'_str'}";
49 $atts->{'_str'} = "$h:$n " . $atts->{'_str'};
50 print "$atts->{'_str'}\n";
51 undef $message;
52 }

Step-by-step code walkthrough:

Lines 1 to 4
Initialisation of the basics needed for this snippet, XML::Parser, of course, and LWP::Simple to get the chatterbox ticker.
Line 8
LWP::Simple get the requested URL, and put the content of the page in the $cb_ticker scalar.
Lines 11 to 16
The most interesting part, no doubt. We create here a new XML::Parser object. The Parser can come in different styles, but when you have to deal with simple data, like the CB ticker, the Handlers way is the easiest (see also the Subs style, as it is really close to this one).

For this object, we define four handlers subs, each representing a different state in the parsing process.

The 'Start' handler is called whenever a new element (or tag, HTML-wise) is found. The sub given is called with the expat object, the name of the element, and a hash containing all the atrributes of this element.
The 'End' is called whenever an element is closed, and is called with the same parameters as the 'Start', minus the attributes.
The 'Char' handler is called when the parser finds something which is not mark-up (in our case, the text enclosed in the <message> tag).
Finally, the 'Default' handler is called, well, by default, when anything else matching the three other handlers is called.
Line 17
The line that does all the magic, parsing and calling all your subs for you at the right moment.
Lines 20-25: the Start handler
We only want to deal with the <message> elements (those containing what it is being said in the Chatterbox) so we'll happily skip every other element.

We got a hash with the attributes of the element, and we're going to use this hash to store the string that will contain the text to be displayed in the $atts{'_str'}

Lines 27-30: the End handler
Once we've reached the end of a message element, we format all the info we have gathered and prints them via the format_message sub.
Lines 32-35: the Char handler
This sub gets all the strings returned by the parser and appends it to the string to be finally displayed
Line 37: the Default handler
It does nothing, but it doesn't have to figure out what to do with this!
Lines 39-52
This subroutine mangles all the info we got from the XML file, with bad regexes and all, and prints the formatted text in a hopefully readable way. Please note that XML::Parser handled all of the decoding of the < and > entities that were included in the original XML file
We now have a complete and simple parser, ready to analyse, extract, report everything inside the Chatterbox XML ticker!

That's all for now, here are some links you may find useful:

Most of mirod's nodes (and especially his review of XML::Parser)
davorg's Data Munging with Perl
Thanks to mirod, arhuman and danger for the review

2008年4月18日 星期五

Write XML Documents by using Perl

These are two useful web pages.

http://search.cpan.org/~josephw/XML-Writer-0.604/Writer.pm

http://www.xml.com/pub/a/2001/04/18/perlxmlqstart1.html

For simplely, you can refer the usage of XML::Writer.

Following are part of content in these web pages, you can look out for them directly.

========


use XML::Writer;
use IO::File;

my $output = new IO::File(">output.xml");
my $writer = new XML::Writer(OUTPUT => $output);

$writer->startTag("greeting", "class" => "simple");
$writer->characters("Hello, world!");
$writer->endTag("greeting");
$writer->end();
$output->close();


========


use XML::Writer;
require "files/camelid_links.pl";

my %camelid_links = get_camelid_data();
my $writer = XML::Writer->new();

$writer->xmlDecl();
$writer->startTag('html');
$writer->startTag('body');

foreach my $item ( keys (%camelid_links) ) {
$writer->startTag('a', 'href' => $camelid_links{$item}->{url});
$writer->characters($camelid_links{$item}->{description});
$writer->endTag('a');
}

$writer->endTag('body');
$writer->endTag('html');
$writer->end();

2008年4月8日 星期二

The type 'System.Web.UI.ScriptManager' is ambiguous: it could come from assembly

Problem:

Encounter error message,


The type 'System.Web.UI.ScriptManager' is ambiguous: it could come from assembly

'C:\WINDOWS\assembly\GAC_MSIL\System.Web.Extensions\1.0.61025.0__31bf3856ad364e35\System.Web.Extensions.dll' or from assembly

'C:\WINDOWS\assembly\GAC_MSIL\System.Web.Extensions\3.5.0.0__31bf3856ad364e35\System.Web.Extensions.dll'.

Please specify the assembly explicitly in the type name.



You may encounter this problem after migrating your application to other host.

========

Solution:

My solution is
1.Delete all files in your bin folder. You may want to backup all of them first.
2.Remove the reference of System.Web.Extensions and System.Web.Extensions.Design from your project(application). They should be version 1.0.61025.0.
3.Re-add System.Web.Extensions and System.Web.Extensions.Design into your project(application). Be sure to include the new version, 3.5.0.0.
4.Modify these two line in your Web.config.


<add assembly="System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35">

<add assembly="System.Web.Extensions.Design, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35">


change the version attribute


<add assembly="System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35">

<add assembly="System.Web.Extensions.Design, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35">


There are two solutions I refered.
http://weblogs.asp.net/javiervillarreal/archive/2008/01/30/the-type-system-web-ui-scriptmanager-is-ambiguous-it-could-come-from-assembly.aspx
and
http://www.eggheadcafe.com/aspnet/how-to/1858840/the-type-systemwebuis.aspx

2008年4月7日 星期一

Very Good PKZIP Command Line Reference

This PKZIP command line reference really help me alot.

This is the origin page.
http://www.uwm.edu/~dtoth/pkzip.html

Following is the content "COPY" from the link shown above.
====

PKZIP
Command Line Reference


This document was created to introduce you to the
command line version of PKZIP. One of the significant differences between
this version of PKZIP and previous versions of PKZIP/PKUNZIP is the consolidation
of compression and extraction (zip/unzip) functionality into a single program.
In other words, the same program compresses and extracts files.
Additionally, the command line syntax has been changed. This was done to
make PKZIP easier to understand and use for the novice and power user alike.
Hopefully, you will find all of the functionality of previous versions
of PKZIP with a simpler more intuitive user interface.


If you have used earlier command line versions of
PKZIP (e.g. PKZIP 2.04g), you may find the PKZIP
Command Line Translation Table
helpful.


Please keep in mind that although this document does
include basic information to help you get started using PKZIP, it is not
a user's manual. The Registered and Licensed versions of PKZIP come with
extensive documentation including a comprehensive user's manual. The PKZIP
User's Manual includes such things as tutorials as well as in depth discussions
of PKZIP's advanced features.


PKZIP Usage:

Usage: pkzip25 [command] [options] zipfile [@list]
[files...]


Examples:

     View .ZIP file contents:
pkzip25 zipfile


     Create a .ZIP file: pkzip25
-add zipfile file(s)...


     Extract files from .ZIP:
pkzip25 -extract zipfile


These are only basic examples of PKZIP's capability

PKZIP Command Reference:

An alphabetical listing of available PKZIP commands
and options follows. You may wish to scroll through the entire list or
click on one of the hyperlinks below to go directly to the specified command/option
section.

PKZIP Commands:











Add 

Comment 

Configuration 

Console

Default 

Delete 

Extract 

Fix

Header 

Help 

License 

Print

Sfx 

Test 

Version 

View


PKZIP Options:











204 

After 

Attributes 

Authenticity 

Before 

Comment 

Decode 

Directories 

Encode 

Exclude 

Fast 

Filetype 

Header

ID 

Include 

Level 

Links 

ListChar 

ListSfxTypes 

Locale  (OS/2) 

Locale  (DOS/UNIX) 

Lowercase 

Mask 

Maximum 

More 

Move

NameSfx 

NameType 

NoExtended 

NoFix 

Normal 

NoZipExtension 

OptionChar 

Overwrite 

Password 

Path 

Permission 

Preview 

Recurse

Sfx 

Shortname 

Silent 

Sort 

Span 

Speed 

Store 

Temp 

Times 

Translate 

Volume 

Warning 

Zipdate




This document contains reference information on every
PKZIP command and option. For each command/option, the following information
is provided:

































Category:Represents:
Name/DescriptionThe full name
of the command/option and a brief description of what that command/option
does.
 

If the command/option can be configured
(defaulted) in the Configuration file, the word "configurable" appears
after the description.

Value(s) The value(s)
associated with this command/option, including the "default" value for
each.
 

If a command/option does not have an
associated value, the phrase "no suboptions" appears. 

Example
usage
An example
of how to include this command/option in your PKZIP command line, including
possible abbreviations. For most options, you can abbreviate the command/option.
These abbreviations are illustrated in the examples used in this appendix.
Used withThis command
can be used for compression, extraction, viewing, testing, a combination,
or as a stand-alone (none of the above). 



Note: Most commands and options documented
here work in all versions of PKZIP. In instances where a command, option,
or suboption is specific to a platform or operating system, the document
will indicate as much. (e.g. UNIX,
DOS, OS/2).


Information on each command/option follows:






















































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































Name/Description:Value(s):Example
usage:
Used
with:
204 

turns on PKZIP for DOS 204g compatibility 

configurable

no suboptions 

----------------------------- 

no default value

pkzip25 -add
-204 save.zip *
add
Name/Description:Value(s):Example
usage:
Used
with:
add 

add files to a .ZIP file 

configurable

all
- compress new files and all existing files
 

freshen - compress only files
that exist in the .ZIP and that have changed
 

update - compress new and update
existing files
 

incremental - compress only
files that have the archive attribute on and subsequently turns off the
archive attribute (DOS, OS/2)
 

-incremental - compress only
files that have the archive attribute on and does not turn off the archive
attribute (DOS OS/2)
 

----------------------------- 

default = all

pkzip25 -add
save.zip *.doc
 

pkzip25 -add=freshen save.zip *.doc 

pkzip25 -add=increm save.zip *.doc 

pkzip25 -add=-increm save.zip *.doc

stand-alone
Name/Description:Value(s):Example
usage:
Used
with:
after 

process files that are newer than,
or equal to, a specified date
 

configurable

any date in
format specified in Country-Settings or the locale option
 

e.g. the US date format is: 

mmddyy 

or 

mmddyyyy 

----------------------------- 

no default value

for compression: 

pkzip25 -add -aft=091595 save.zip *.doc 

for extraction: 

pkzip25 -ext -after=091595 save.zip
*.doc

add, extract,
delete, test, view
Name/Description:Value(s):Example
usage:
Used
with:
attributes 

stores files with the specified file
attribute information in the .ZIP file
 

configurable 

(DOS, OS/2)

hidden
- compress hidden files
 

system - compress system files 

readonly - compress read-only
files
 

all - compress all types of
files
 

none - don’t compress files
that have hidden, system, or read-only attributes; overrides the default
attributes setting in config file
 

----------------------------- 

default = readonly 

default if used on command line without
a sub-option = all

pkzip25 -add
-attr=system,hidden save.zip *
add
Name/Description:Value(s):Example usage:Used with:
authenticity 

embed Authenticity Verification (AV)
information in a .ZIP file; functionality available in fully registered versions of PKZIP only
 

note: the authenticity option may prevent PKZIP from storing and/or preserving certain Unix file permission attributes

no suboptions 

----------------------------- 

no default value

pkzip25 -add -auth save.zip
*.doc
add
Name/Description:Value(s):Example
usage:
Used
with:
before 

process files that are older than a
specified date
 

configurable

any date in
format specified in Country-Settings or the locale option
 

e.g. the US date format is: 

mmddyy 

or 

mmddyyyy 

----------------------------- 

no default value

for compression: 

pkzip25 -add -bef=091595 save.zip *.doc 

for extraction: 

pkzip25 -ext -bef=091595 save.zip *.doc

add, extract,
delete, test, view
Name/Description:Value(s):Example
usage:
Used
with:
comment 

include a text comment for individual
files within a .ZIP file
 

configurable

all
- all files within .ZIP file
 

unchanged - only existing files
that have not changed
 

add - only new files 

freshen - only existing files  

update - existing and new files 

none - turn off comment  

----------------------------- 

default = add

pkzip25 -add
-com=all save.zip *.doc
 
add, stand-alone
Name/Description:Value(s):Example
usage:
Used
with:
configuration 

define default values for most PKZIP
commands/options

any configurable
command or option
specified in the previous chapters
 

----------------------------- 

no default value

pkzip25 -config
-extract=freshen
 

to see the current configuration values,
type:
 

pkzip25 -config

stand-alone 
Name/Description:Value(s):Example
usage:
Used
with:
console 

perform a "mock" extract and display
files on your screen

no suboptions 

----------------------------- 

no default value

pkzip25 -console
save.zip *.txt
stand-alone
Name/Description:Value(s):Example
usage:
Used
with:
decode 

instructs PKZIP to verify the encoding
scheme (e.g. UUEncoded file) and process archived files in the event that
PKZIP is unable to detect the file type automatically
 

note: PKZIP will normally detect
different encoding schemes and automatically process archived files; a
command line option is usually not necessary to enable this feature

no suboptions  

-----------------------------  

no default value

pkzip25 -extract
-decode save.hqx 
extract, test,
view 
Name/Description:Value(s):Example
usage:
Used
with:
default 

reset the original defaults for the
commands-options in the config file

no suboptions 

----------------------------- 

no default value

to reset all
defaults:
 

pkzip25 -default 

stand-alone 
Name/Description:Value(s):Example
usage:
Used
with:
delete 

remove files from a .ZIP file

file(s) to
delete
 

----------------------------- 

no default value

for individual
files:
 

pkzip25 -del save.zip doc1.txt 

for a specific file pattern:  

pkzip25 -del save.zip *.doc

stand-alone
Name/Description:Value(s):Example
usage:
Used
with:
directories 

store directory path names during compression,
or recreate directory path names while extracting
 

includes subdirectories (recurse) 

configurable 

note: using this command is
the same as combining the path and recurse commands

current
- store path information relative to the current path
 

root or full - store
the entire path beginning at the root directory
 

specify - store the path information
for each file being compressed (or recreates for each file being extracted),
as specified on the command line
 

relative - store the directory
path relative to the current working directory of the drive(s) specified
(DOS)
 

none - overrides directory path
information in configuration file
 

----------------------------- 

default = none 

default if used on command line without
a sub-option = current

compression
example (assumes you are in "/wp"):
 

pkzip25 -add -dir=root save.zip wp/docs/* 

the path stored would be "wp/docs/*" 

pkzip25 -add -dir=current save.zip
wp/docs/*
 

the path stored would be: "docs/*" 

extraction example:  

pkzip25 -ext -direct save.zip /* 

note: UNIX users should utilize
the include option or place quotation marks around wildcard designations
to bypass automatic wildcard expansion by the shell, which may restrict
your pattern search
 

add, extract
Name/Description:Value(s):Example
usage:
Used
with:
encode 

creates archive in the UUEncode format 

note: PKZIP will create two
files when the encode option is invoked; a .ZIP archive (e.g. save.zip)
as well as UUEncoded version of the .ZIP file (e.g. save.uue) are created

no suboptions 

-----------------------------  

no default value

pkzip25 -add
-encode save.zip *
add
Name/Description:Value(s):Example
usage:
Used
with:
exclude 

exclude files from being compressed
or extracted
 

configurable 

note: you must specify a sub-option
(e.g. file pattern or list file name preceded by an appropriate list character
"@") with the exclude option

the file(s)
or file pattern (for example, *.doc) being excluded
 

----------------------------- 

no default value

compression
example:
 

pkzip25 -add -excl=*.doc save.zip 

extraction example: 

pkzip25 -ext -excl=*.txt save.zip 

setting exclude default: 

pkzip25 -config -excl=*.txt 

note: when you use the exclude
option with the configuration command, PKZIP prompts you to configure the
exclude default for add and/or extract operations

add, extract,
delete, test, view
Name/Description:Value(s):Example
usage:
Used
with:
extract 

extract files from a .ZIP file 

configurable

all
- all files in .ZIP file
 

freshen - only files in the
.ZIP file that exist in the target directory and that are "newer" than
those files will be extracted
 

update - files in the .ZIP file
which already exist in the target directory and that are "newer" than those
files as well as files that are "not" in the target directory will be extracted
 

----------------------------- 

default = all

pkzip25 -ext=up
save.zip 
stand-alone
Name/Description:Value(s):Example
usage:
Used
with:
fast 

set the level of compression to "fast"
or level 2 
 

configurable

no suboptions 

----------------------------- 

no default value

pkzip25 -add
-fast save.zip *.doc
 

pkzip25 -config -fast

add
Name/Description:Value(s):Example
usage:
Used
with:
filetype 

processes files with the specified
file type information in the .ZIP file
 

(UNIX) 

note:a "-" before a filetype
sub-option tells PKZIP to exclude the specified filetype(s) regardless
of the default configuration setting (e.g. -filetype=-hidden will exclude
hidden files regardless of the default configuration setting) 
 

hidden
- include/exclude filenames that have a dot "." in the first position of
the filename (e.g. .profile)
 

pipe - include/exclude pipe
files. These are files having a file mode starting with "p" (e.g. prwxrw-rw-)
 

slink - include/exclude symbolic
links. These are files having a file mode starting with "l" (e.g. lrw-rw-rw-)
 

hlink -include/exclude hard
linked files. These are linked files that are not symbolic links. They
are files with a link count >1
 

none - exclude all of the above
file types; Generally, this option should be followed by one, or more,
file types. This results in just the type(s) specified being included in
the ZIP file. For example, -filetype=none, pipe results in only PIPE files
being included
 

all - include all of the above
file types
 

regular - include/exclude regular
files
 

----------------------------- 

default = regular

pkzip25 -filetype=all
save.zip
add, extract
Name/Description:Value(s):Example
usage:
Used
with:
fix 

recover a corrupt .ZIP file

no suboptions 

----------------------------- 

no default value

pkzip25 -fix
save.zip
stand-alone
Name/Description:Value(s):Example
usage:
Used
with:
header 

create a comment for a .ZIP file, which
will appear in the header area of the .ZIP file
 

configurable

a text string
or file specified with a list file character (e.g. @) that represents the
header information 
 

----------------------------- 

no default value

to include
specific text:
 

pkzip25 -add -hea save.zip *.doc 

note: when you type this command,
PKZIP will prompt you for the header text
 

to include an existing file: 

pkzip25 -add -hea=@text.doc save.zip
*.doc

add, stand-alone
Name/Description:Value(s):Example
usage:
Used
with:
help 

display Help for PKZIP

any command
or option for which help is desired
 

----------------------------- 

no default value

pkzip25 -help 

pkzip25 -help=add 

in this example you are specifying
a specific command (add) for which you wish to view the Help file

stand-alone
Name/Description:Value(s):Example
usage:
Used
with:
id 

preserve the user ID (UID) and/or group
ID (GID) on extraction
 

(UNIX) 

note: the user who extracts
files with preserved UID and GID information must have the same UID as
is archived in the .ZIP file or root (superuser) file privileges 

userid
- retain the user ID on extraction
 

groupid - retain the group ID
on extraction
 

all - retain both the user ID
and group ID on extraction
 

none - retain neither the user
ID or group ID on extraction
 

----------------------------- 

no default value

pkzip25 -extract
-id=userid save.zip
extract
Name/Description:Value(s):Example
usage:
Used
with:
include 

include files to compress or extract 

configurable 

note: you must specify a sub-option
(e.g. file pattern or list file name preceded by an appropriate list character
"@") with the exclude option

the file(s)
or file pattern (for example, *.doc) being included
 

----------------------------- 

no default value

pkzip25 -add
-include=*.doc save.zip
 

in this example, only .doc files will
be compressed
 

pkzip25 -config -include=*.txt 

in this example, you are setting up
.txt files as the files that you always want to compress or extract, until
you change the default or override from the command line with the exclude
option
 

note: when you use the include
option with the configuration command, PKZIP prompts you to configure the
include default for add and/or extract operations

add, extract,
delete, test, view
Name/Description:Value(s):Example
usage:
Used
with:
level 

set the level of compression 

configurable

any digit from
0 through 9, with 0 being no compression at the fastest speed, and 9 being
the most compression at the slowest speed
 

----------------------------- 

default = level 5 (normal)

pkzip25 -add
-lev=9 save.zip *.doc
add
Name/Description:Value(s):Example
usage:
Used
with:
license 

display the product license information
for PKZIP

no suboptions 

----------------------------- 

no default value

pkzip25 -licstand-alone
Name/Description:Value(s):Example
usage:
Used
with:
links 

specify that linked files be followed
or preserved in a .ZIP archive
 

(UNIX) 

note:
following a link results in a larger .ZIP file since two copies of file
data are compressed as though each link is a separate file

hlink
- hard links will be followed (stored) rather than preserved
 

slink - symbolic links will
be followed (stored) rather that preserved
 

all - symbolic and hard links
will be followed rather than preserved
 

none - symbolic and hard links
will be preserved
 

----------------------------- 

default = none

pkzip25 -add
-filetype=hlink   -links=hlink save.zip
 

this example compresses regular and
hard linked files as well as duplicates link and file data for each hard
linked file added to the .ZIP file 

add, filetype 

note: you must use both the
add command and filetype option with the links option 

Name/Description:Value(s):Example
usage:
Used
with:
listchar 

set the list character to the specified
ASCII character for list files
 

configurable

any valid single
character
 

----------------------------- 

default = @

pkzip25 -config
-listchar=+
add, extract,
delete, test, view
Name/Description:Value(s):Example
usage:
Used
with:
listsfxtypes 

display a list of the types of SFX
files that can be created with PKZIP

no suboptions 

----------------------------- 

no default value

pkzip25 -listsfxtypes stand-alone
Name/Description:Value(s):Example
usage:
Used
with:
locale 

change the system locale environment
value that defines the valid formats for all date and time fields entered
using PKZIP
 

configurable 

(OS/2)

a valid country
name (e.g. us, germany, france)
 

environment - PKZIP will attempt
to use the environment variable defined by the operating system
 

----------------------------- 

default = US 

default if used on command line without
a sub-option = environment

pkzip25 -config
-locale=germany
 

pkzip25 -add -locale=germany test.zip
*.doc
 

pkzip25 -add -locale=environment test.zip
*.doc

add, extract,
delete, test, view 
Name/Description:Value(s):Example
usage:
Used
with:
locale 

set the default PKZIP time and date
settings to match your system time and date formats
 

configurable 

(DOS, UNIX)

no suboptions 

----------------------------- 

default = (time=12-Hour; date=MMDDYY)

pkzip25 -config
-locale
 

pkzip25 -add -locale test.zip *.doc

add, extract,
delete, test, view
Name/Description:Value(s):Example
usage:
Used
with:
lowercase 

extracts
file name(s) in lower case regardless of how it was originally archived 
 

(UNIX)

no suboptions 

----------------------------- 

no default value

pkzip25 -extract
-lowercase save.zip *
 
extract
Name/Description:Value(s):Example
usage:
Used
with:
mask 

remove file attributes of files within
a .ZIP file or when extracting
 

note: you can only remove the
attributes that have been stored, as defined by the attribute command
 

configurable 

(DOS, OS/2)

hidden
- hidden attributes
 

system - system attributes 

readonly - read-only attributes 

none - no attributes (turns
off attribute mask in the PKZIP Configurations Settings file for this instance
only)
 

all - all attributes 

----------------------------- 

default (compress) = none 

default (extract) = all 

default if used on command line without
a sub-option (compress and extract) = all

pkzip25 -add
-attr=hidden 
 

-mask=hidden save.zip 

pkzip25 -extract -mask=none save.zip  

pkzip25 -config -mask=hidden 

note: when you use the mask
option with the configuration command, PKZIP prompts you to configure the
mask default for add and/or extract operations 
 

add, extract
Name/Description:Value(s):Example
usage:
Used
with:
maximum 

set the level of compression to the
highest level, but lowest speed
 

configurable

no suboptions 

----------------------------- 

no default value

pkzip25 -add
-max save.zip *.doc
 

pkzip25 -config -max

add
Name/Description:Value(s):Example
usage:
Used
with:
more 

pause after one screen of output and
prompt to continue
 

configurable

the number
of rows of information you want to consist of a screen
 

----------------------------- 

default = one screen of information

pkzip25 -view
-more=22 save.zip
 

pkzip25 -config -more 

note: when you use the more
option with the configuration command, PKZIP prompts you to configure the
more default for add, extract, and/or view operations

all commands
Name/Description:Value(s):Example
usage:
Used
with:
move 

remove the files from the source drive
after compression (files will reside only in .ZIP file)
 

configurable

no suboptions 

----------------------------- 

no default value

pkzip25 -add
-move save.zip *.doc
 

pkzip25 -config -move 

note: if the move option is
enabled by default in the configuration file, PKZIP will display a confirmation
prompt every time you attempt to modify the configuration file

add
Name/Description:Value(s):Example
usage:
Used
with:
namesfx 

specify a file name when converting
to a self-extracting file

a valid file
name (e.g. filename.exe) 
 

----------------------------- 

no default value

pkzip25 -sfx
-namesfx=test.exe docs.zip
sfx
Name/Description:Value(s):Example
usage:
Used
with:
nametype 

specify the format in which you wish
to extract file(s)
 

configurable  

(OS/2)

auto
- auto-detection of file system and extraction format
 

short - files are extracted
in 8+3 format
 

long - files are extracted in
same format that they were originally added in
 

----------------------------- 

default = auto 

default if used on command line without
a sub-option = short

pkzip25 -extract
-nametype=long test.zip /temp
extract
Name/Description:Value(s):Example
usage:
Used
with:
noextended 

suppress the storage of extended attribute information (excluding file permission attributes) when adding files or suppress the storage of file permission attributes when extracting files  

note:by default PKZIP will suppress ownership (e.g. UID/GID) attributes on extraction; you may use the id option to preserve these attributes

configurable

no suboptions 

----------------------------- 

no default value

pkzip25 -add
-noextended save.zip *
add, extract
Name/Description:Value(s):Example
usage:
Used
with:
nofix 

suppress the "attempt to fix" prompt
if PKZIP encounters errors in a .ZIP file
 

configurable

no suboptions 

----------------------------- 

no default value

pkzip25 -add
-nofix save.zip *.doc
add, extract,
delete, test, view
Name/Description:Value(s):Example
usage:
Used
with:
normal 

set the level of compression to 5;
for the best balance of compression and speed 
 

configurable

no suboptions 

----------------------------- 

no default value

pkzip25 -add
-normal save.zip
 

pkzip25 -config -normal

add
Name/Description:Value(s):Example
usage:
Used
with:
nozipextension 

suppress the adding of a .ZIP extension
to the .ZIP file name
 

configurable

no suboptions 

----------------------------- 

no default value

pkzip25 -add
-nozipextension file.ibm *.doc
all commands
Name/Description:Value(s):Example
usage:
Used
with:
optionchar 

set the option character to the specified
ASCII character
 

configurable

any valid single
character
 

----------------------------- 

default = - (dash)

pkzip25 -opt=+
+add save.zip *.doc
 

pkzip25 -config -option=+

all commands
Name/Description:Value(s):Example
usage:
Used
with:
overwrite 

determine whether or not to overwrite
files on your hard drive with the files being extracted
 

configurable 

prompt
- prompt every file individually on whether to overwrite a file that has
the same name as the one being extracted
 

all - overwrite all files that
have a corresponding file on the hard drive
 

never - never overwrite a file
that has a corresponding file on the hard drive
 

----------------------------- 

default = prompt 

default if used on command line without
a sub-option = all

pkzip25 -ext
-over=all save.zip
 
extract
Name/Description:Value(s):Example
usage:
Used
with:
password 

include a password with your .ZIP file 

configurable

your password,
or no value
 

----------------------------- 

no default value

to include
password in the command:
 

pkzip25 -add -pass=beowulf save.zip 

to have PKZIP prompt you for a password
"after" you type the command:
 

pkzip25 -add -pass save.zip

add, extract,
test
Name/Description:Value(s):Example
usage:
Used
with:
path 

store directory path names for files
within a .ZIP file
 

configurable

current
-stores the path from the current directory
 

root/full - store the
entire path beginning at the root of the drive; also referred to as "full"
path
 

specify - store the path as
specified in your pkzip command 
 

relative - store the directory
path relative to the current working directory of the drive(s) specified
(DOS)
 

none - no path information stored 

----------------------------- 

default = none 

default if used on command line without
a sub-option = current

assuming in
you are in "/temp":
 

pkzip25 -add -path=root save.zip docs/* 

(the complete path is stored including
"temp/docs/")
 

pkzip25 -add -path=current save.zip
wp/docs/*
 

(the path stored would be "docs/wp") 

add
Name/Description:Value(s):Example
usage:
Used
with:
permission 

restores and/or sets the mode of a
file on extraction
 

(UNIX) 

note: PKZIP will automatically
restore read, write, and execute permission attributes (assuming they have
been stored in the .ZIP file) on extraction; the permission option is only
necessary if you wish to restore other attributes (e.g. Set user ID, Set
Group ID, sticky bit) or modify permissions and/or other attributes, stored
with the archived files, on extraction

octal mode
value
 

----------------------------- 

no default value

pkzip25 -extract
-permission save.zip
 

in this example PKZIP will preserve
all permissions as well as other attributes on extraction
 

pkzip25 -extract -permisssion=4111
save.zip *
 

in this example PKZIP will preserve
and/or attempt to modify all permissions as well as other attributes on
extraction
 

note: the permissions option can only add permissions; it cannot take away permissions from an existing mode setting; the noextended option used in conjunction with your umask setting may be used to suppress permission attributes

extract
Name/Description:Value(s):Example
usage:
Used
with:
preview 

preview the results of a set of commands
or options without actually performing the task represented by that command/option

no suboptions 

----------------------------- 

no default value

pkzip25 -add
-preview save.zip
 
add
Name/Description:Value(s):Example
usage:
Used
with:
print 

print a file within a .ZIP file 

(DOS, OS/2)

the print device
use, for example, "lpt1"
 

----------------------------- 

default = the default printer on your
system

pkzip25 -print=lpt1
save.zip readme.txt
 

if you do not specify a print device,
the "default" printer is used

stand-alone
Name/Description:Value(s):Example
usage:
Used
with:
recurse 

search subdirectories for files to
compress
 

configurable

no suboptions 

----------------------------- 

no default value

pkzip25 -add
-rec save.zip addendum.doc
 

note: UNIX users should utilize
the include option or place quotation marks around wildcard designations
to bypass automatic wildcard expansion by the shell, which may restrict
your pattern search

add
Name/Description:Value(s):Example
usage:
Used
with:
sfx 

create a self-extracting .ZIP file
(.EXE file), or convert an existing .ZIP file to a .EXE file
 

configurable 

note: for a listing of available
self extractors, use the listsfxtypes option

dosfull
- create a DOS- formatted self-extractor
 

jrdos - create a DOS junior
self-extractor
 

win16 - create a Windows 16-bit
self-extractor
 

----------------------------- 

default = (create an sfx native to
the operating system)

for a new .ZIP
file:
 

pkzip25 -add -sfx save 

to convert an existing .ZIP file: 

pkzip25 -sfx save.zip

add, stand-alone
Name/Description:Value(s):Example
usage:
Used
with:
shortname 

convert .ZIP file name in long file
name format to a DOS or equivalent "short" file name
 

note: PKZIP includes sub-options
for both OS/2 and DOS because of the differences in the way each OS handles
short file names
 

configurable

dos
- convert .ZIP file to a dos-equivalent short file name
 

os2 - convert .ZIP file to an
-equivalent short file name
 

----------------------------- 

no default value

pkzip25 -add
-short=dos save.zip
add
Name/Description:Value(s):Example
usage:
Used
with:
silent 

suppress all screen display output 

configurable 

note: errors and warnings are
displayed whether the silent option is specified or not, however, prompts
for other PKZIP operations are not displayed (e.g. Password)

no suboptions 

----------------------------- 

no default value

pkzip25 -add
-silent save.zip *.doc
 

pkzip25 -config -silent 

note: if the silent option is
enabled by default in the configuration file, PKZIP will display a confirmation
prompt every time you attempt to modify the configuration file

all commands
Name/Description:Value(s):Example
usage:
Used
with:
sort 

sort files within .ZIP file based on
specific criteria (for example, by file size)
 

configurable 

note: the crc and ratio sub-options
will not work with the add command and sort option
 

crc
- sort by CRC value
 

date - sort by file date of
file
 

extension - sort by file extension 

name - sort alphabetically by
name
 

natural - sort in the order
that the file was compressed
 

ratio - sort by compression
ratio
 

size - sort by the original,
uncompressed size of the file ("length" in display)
 

none - do not sort (same as
natural)
 

----------------------------- 

default = natural 

default if used on command line without
a sub-option = name

pkzip25 -add
-sort=date save.zip *.doc
 

pkzip25 -config -sort=date 

note: when you use the sort
option with the configuration command, PKZIP prompts you to configure the
mask default for add, extract, and/or view operations

add, extract,
test, view
Name/Description:Value(s):Example
usage:
Used
with:
span 

forces disk spanning in the event that
PKZIP is unable to detect the fact that destination directory is on removable
media
 

note: the spanning process should
proceed automatically; a command line option is usually not necessary to
enable this feature
 

(DOS, OS/2)

no suboptions 

----------------------------- 

no default value

pkzip25 -add
-span a:\save.zip *.doc
add
Name/Description:Value(s):Example
usage:
Used
with:
speed 

sets the level of compression to 1,
which is the least but fastest compression
 

configurable

no suboptions 

----------------------------- 

no default value

pkzip25 -add
-speed save.zip *.doc
 

pkzip25 -config -speed

add
Name/Description:Value(s):Example
usage:
Used
with:
store 

sets the level of compression to 0
(no compression), and only stores the files within the .ZIP file
 

configurable

no suboptions 

----------------------------- 

no default value

pkzip25 -add
-store save.zip *.doc
 

pkzip25 -config -store 

add
Name/Description:Value(s):Example
usage:
Used
with:
temp 

creates the temporary .ZIP file required
by PKZIP, on specified drive 
 

note: the temp option only works
when updating an existing .ZIP file

the drive and/or
path.
 

e.g. C: or /root/temp 

----------------------------- 

no default value

pkzip25 -add
-temp=Z:\PUBLIC test.zip *.txt
 

this example updates the .ZIP file
test.zip and uses the Z:\PUBLIC directory location for the temp file
 

pkzip25 -add -temp=/temp test.zip *.txt 

this example updates the .ZIP file
test.zip and uses the /temp directory location for the temp file
 

 

add
Name/Description:Value(s):Example
usage:
Used
with:
test 

test the integrity of files within
a .ZIP file
 

configurable

all
- all files in .ZIP file
will
be tested
 

freshen - only those files in
the .ZIP file which already exist in the extract directory and that have
a file modification date newer that the files already in the directory
will be tested
 

update - files in the .ZIP file
which already exist in the target directory and that are "newer" than those
files and files that are "not" in the target directory will be tested
 

----------------------------- 

default = all

pkzip25 -test
save.zip
stand-alone
Name/Description:Value(s):Example
usage:
Used
with:
times 

specify whether file access, creation,
and modification times are to be preserved
 

(DOS, UNIX) 

 

access
- restores the time of last access to file(s) on extraction
 

modify - restores the time of
last modification to file(s) on extraction
 

create - restores the time of
creation to file(s) on extraction (DOS)
 

all - all file times are restored 

none - file times are not restored 

------------------------------- 

default = none 

pkzip25 -extract
-times=access save.zip
 
extract
Name/Description:Value(s):Example
usage:
Used
with:
translate 

analyze text files in a .ZIP file and
if necessary translate the carriage return/newline sequence for compatibility
with a specified operating system
 

(UNIX) 

none
- no translation is performed on text files
 

dos - translates text files
so lines end with a return/newline pair as per the DOS standard
 

mac - translates text files
so lines end with a single carriage return as per the MacOS standard
 

unix - translates text files
so lines end with a single newline as per the UNIX (i.e. POSIX) standard
 

-------------------------------  

default = none 

default if used on command line without
a sub-option = native operating system compatibility translation

pkzip25 -extract
-translate=unix save.zip
 
extract
Name/Description:Value(s):Example
usage:
Used
with:
version 

determine the version of PKZIP you
are running
 

note: PKZIP also returns the
version number to the shell by way of setting the error level; the version
number value is passed directly to the shell and as such is not viewable
by the user 

major
- returns the major version number of the release
 

minor - returns the minor number
of the release (e.g. - if the version number is 2.5.1, the value returned
is 5)
 

step - returns the step, or
patch value. (e.g. - if the version is 2.04.01, the step value returned
is 1)
 

----------------------------- 

default = major

pkzip25 -version stand-alone
Name/Description:Value(s):Example
usage:
Used
with:
view 

display information about the files
within a .ZIP file, for example, the compressed size of a file
 

configurable

brief
- present information in the most compact manner
 

details - present information
in the most detailed manner
 

normal - present information
in the normal manner
 

----------------------------- 

default = normal

pkzip25 -view
save.zip
stand-alone
Name/Description:Value(s):Example
usage:
Used
with:
volume 

store/restore the volume label with
the .ZIP file
 

configurable 

(DOS, OS/2)

a drive letter
(for example, C)
 

----------------------------- 

default = no volume label 

default if used on command line without
a sub-option = current drive

pkzip25 -add
-volume=C save.zip *.docs
add, extract
Name/Description:Value(s):Example
usage:
Used
with:
warning 

pause after every warning, and prompt
you to continue or not
 

configurable

no suboptions 

----------------------------- 

no default value

pkzip25 -ext
-warn save.zip *
add, extract,
test, view
Name/Description:Value(s):Example
usage:
Used
with:
zipdate 

set the file modification date of the
.ZIP file 
 

configurable

newest
- set to the date of the "newest" file within the .ZIP file
 

oldest - set to the date of
the "oldest" file within the .ZIP file
 

retain - retain the original
date of the .ZIP file (the date on which the .ZIP file was created)
 

none - disable the .ZIP file
date in the config file, and set the .ZIP date as the last modification
date
 

----------------------------- 

default = the current date 

default if used on command line without
a sub-option = retain

pkzip25 -add=update  

-zipdate=retain save.zip *.txt
add

 

PKZIP
Command Line Translation Table


 



















































































































































































































































































































PKZIP
2.04 Command:
PKZIP
2.50 Command/Option
pkzippkzip25
-add
-b<drive:path>-temp=drive:path
-c/-C-comment(all,unchanged,add,freshen,update,none)
-d-delete
-e[x|n|f|s|0]-level (0-9)
-ex-maximum
-en-normal
-ef-fast
-es-speed
-e0-store
-f-freshen
-h-help
-i-add=incremental
-i--add=-incremental
-j<h,r,s>-mask=all (hidden,system,readonly)
-J<h,r,s>-mask=none
(default)
-k-zipdate=retain
-m[u|f]-move (with
/add=update or /add=freshen)
-o-zipdate (newest,oldest,retain,none)
-p-path (current,relative,specify)
-P-path=full
-r-recurse
-rp/-rP-directories
(current,full,relative,specify,none)
-s[password]-password (or
-password=xxxx)
-t<date>-after=mmddyy
(or mmddyyyy)
-T<date>-before=mmddyy
(or mmddyyyy)
-u-add=update
-v-view (brief,details,normal)
-w<h,s>W<h,s>-attributes
(hidden,system,readonly,all,none)
-x<filename-exclude=filename
-x@listfile-exclude=@listfile
-z-header
-&-span (to force
if not detected)
-$[d]-volume=drive
pkunzippkzip25
-extract
-c[m]-console (-more)
-d-directories
-e[r][c|d|e|n|p|s]-sort (crc,date,extension,name,ratio,size,natural,none)
-f-extract=freshen
-h-help
-j<h,r,s>-mask=all (default)
(hidden,system,readonly)
-J<h,r,s>-mask=none
-n-extract=freshen
-o-overwrite
(prompt,all,never)
-p[a/b][c][#]-print
-s[password]-password (or
-password=password)
-t-test (all,freshen,update)
-v-view (brief,details,normal)
-x<filespec>-exclude=filename
-x@listfile-exclude=@listfile