INDEX
Perlスクリプトの実行ファイル化
PAR を使うと「Perlスクリプト」を「Windowsの実行ファイル(*.exe)」に出来る。
仕組みとしては、
- Perlのインタープリタ、ライブラリ、スクリプトをひとつにまとめる。
- EXEが実行すると、中のインタープリタでスクリプトが実行される。
なので、
- Perlのインタープリタ(ActivePerlなど)をインストールしなくてもよい。
- 実行ファイルなのでダブルクリックでいきなり実行できる。
- すべてひとつになるのでファイルがデカイ。(中はZIP形式でまとめられているようです)
実行ファイル作成手順
簡単なスクリプト("Hello, world!")を作成。
1 |
#!/usr/local/bin/perl -w ##### Character-code is SHIFT_JIS. Tab-size is 4 space character. ##### ############################################################################### use strict; # restrict unsafe constructs use warnings; # control optional warnings ( as /usr/bin/perl -w ) print "Hello, world!\n"; exit; ############################################################################### ## End Of File (HelloPerlWorld.pl) ## ############################################################################### |
普通にperlでスクリプトを実行。
C:\>perl HelloPerlWorld.pl Hello, world! C:\>
実行ファイル化。
C:\>pp -o HelloPerlWorld.exe HelloPerlWorld.pl
実行ファイルを実行。
C:\>HelloPerlWorld.exe Hello, world! C:\>
ちなみに、以下のように、500byteほどのスクリプトファイルが、1.5Mの実行ファイルになる。
C:\>dir HelloPerlWorld.* 2007/01/12 15:01 1,619,684 HelloPerlWorld.exe 2007/01/12 14:54 496 HelloPerlWorld.pl
ppコマンドオプション
- -o, --output=FILE
- 出力する実行ファイル名。指定しないと "a.exe" となる。
- -i, --icon=FILE
- 実行ファイルのアイコンを指定する。アイコンファイルは、*.ico, *.exe, *.dll が利用できる。ライブラリアイコン(*.exe, *.dll)は、最初のアイコンが利用される。
- -g, --gui
- 実行時にコンソールウインドウを表示しない。
- -a, --addfile=FILE|DIR
- パッケージの中に含めるファイルを指定する。
- -I, --lib=DIR
- (検索する)ライブラリパスを指定する。
- -M, --module=MODULE
- パッケージの中に含めるライブラリを指定する。
- -e, --eval=STRING
- ワンライナースクリプトをパッケージする。
- -h, --help
- ヘルプ(使い方)を表示する。
- -V, --version
- バージョンを表示する。
ActivePerl with PAR のインストール
ActivePerl 5.8.8.817 でインストール後、ActivePerl 5.8.6.811 に落しています。そのためメッセージは 5.8.8.817 のまま。
ActivePerl
当時('06/06/29)の最新版 5.8.8.817 を入れていたが、必要なライブラリのバージョンが合わず実行時(EXE作成時)にエラーになる。今('06/12/27)行うときは、5.8.6(ActivePerl-5.8.6.811) を入れる。
ppm設定
PPMとは、ActivePerl のパッケージ管理システム。モジュールやパッケージを簡単にインストールやアップデートすることが出来る。
デフォルトでは、ActiveState のリポジトリを見に行くようになっている。ので、"bribes"を追加して優先度を上げる。(RAR FAQより)
C:\WINDOWS\system32>ppm3 PPM - Programmer's Package Manager version 3.4. Copyright (c) 2001 ActiveState Software Inc. All Rights Reserved. Entering interactive shell. Using Term::ReadLine::Perl as readline library. Type 'help' to get started. ppm> rep add bribes http://www.bribes.org/perl/ppm Repositories: [1] ActiveState Package Repository [2] bribes ppm> rep up bribes Repositories: [1] bribes [2] ActiveState Package Repository
必要なモジュールのインストール
PPMを利用して、必要なモジュールをインストール(一部アップデート)する。
依存関係も見てくれるようなので、次だけでも良いかもしれない。
ppm> install PAR-Packer
個々のパッケージのインストール(アップデート)とバージョン
ppm> install File-Which ==================== Upgrade 'File-Which' version 0.05 in ActivePerl 5.8.8.817. ====================
ppm> install File-Temp ==================== Install 'File-Temp' version 0.17 in ActivePerl 5.8.8.817. ====================
ppm> install Compress-Zlib Note: Package 'Compress-Zlib' is already installed. ppm> upgrade Compress-Zlib -install -precious Compress-Zlib 1.41: new version 2.001 available in bribes Error: Package 'Compress-Zlib' not found. Please 'search' for it first. ※あれ?
ppm> install Archive-Zip Note: Package 'Archive-Zip' is already installed. ppm> upgrade Archive-Zip -install -precious Archive-Zip 1.16: new version 1.18 available in bribes Archive-Zip 1.16: new version 1.18 available in ActiveState Package Repository Note: Archive-Zip version 1.16 is available from more than one place. Which repository would you like to upgrade from? 1. bribes 2. ActiveState Package Repository Repository? [ActiveState Package Repository] 2 ==================== Upgrade 'Archive-Zip' version 1.18 in ActivePerl 5.8.8.817. ====================
ppm> install Module-ScanDeps ==================== Install 'Module-ScanDeps' version 0.70 in ActivePerl 5.8.8.817. ====================
ppm> install Parse-Binary ==================== Install 'Parse-Binary' version 0.10 in ActivePerl 5.8.8.817. ====================
ppm> install Test-Simple ==================== Install 'Test-Simple' version 0.66 in ActivePerl 5.8.8.817. ====================
ppm> install Win32-Exe ==================== Install 'Win32-Exe' version 0.08 in ActivePerl 5.8.8.817. ====================
ppm> install Digest-SHA ==================== Install 'Digest-SHA' version 5.44 in ActivePerl 5.8.8.817. ====================
ppm> install Module-Signature ==================== Install 'Module-Signature' version 0.54 in ActivePerl 5.8.8.817. ====================
ppm> install Getopt-ArgvFile ==================== Install 'Getopt-ArgvFile' version 1.10 in ActivePerl 5.8.8.817. ====================
ppm> install PAR-Dist ==================== Install 'PAR-Dist' version 0.21 in ActivePerl 5.8.8.817. ====================
ppm> install PAR ==================== Install 'PAR' version 0.970 in ActivePerl 5.8.8.817. ====================
ppm> install PAR-Packer ==================== Install 'PAR-Packer' version 0.970 in ActivePerl 5.8.8.817. ====================
"q"コマンドでPPMを終了して、"pp -V"でPARのバージョンが表示されれば完了
ppm> q C:\WINDOWS\system32>pp -V PAR Packager, version 0.970 (PAR version 0.970) Copyright 2002, 2003, 2004, 2005, 2006 by Audrey Tang <autrijus@autrijus.org>
最終更新時間:2008年11月14日 16時54分00秒 指摘や意見などあればSandBoxのBBSへ。