ヘッダー情報を丸ごと指定してwgetで取得

wgetでよく指定するオプション

認証情報やユーザー情報を指定するにはだいたい以下の2つのオプションを指定する。

ログインユーザー、パスワードを指定する
  --http-user=USER        set http user to USER.
  --http-password=PASS    set http password to PASS.
cookieのファイルを指定する
  --load-cookies=FILE     load cookies from FILE before session.

wgetでcookieを使用する --load-cookies-sqliteオプションだと!?

ヘッダー情報を丸ごと指定する場合

上記のやり方でだいたいはうまくいくと思うけど、たまにダメなときがある。
そんな場合は、ヘッダー情報を丸ごと指定すると上手くいくかもしれない。

1.ping ホスト名でIPアドレスを確認する
2.プロトコル解析

HttpFoxWiresharkMicrosoft Network Monitorなどを使って プロトコル情報を解析する
ここはもっと楽に見る方法があるかも。

3. header情報を丸ごと全部指定

ヘッダー情報-header オプションでを丸ごと全部指定する

wget
--header="User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; ja; rv:1.9.2.8) Gecko/20100722 Firefox/3.6.8 GTB7.1 ( .NET CLR 3.5.30729)"
--header="Accept: text/javascript, text/html, application/xml, text/xml, */*"
--header="Accept-Language: ja,en-us;q=0.7,en;q=0.3"
--header="Accept-Encoding: gzip,deflate"
--header="Accept-Charset: Shift_JIS^,utf-8;q=0.7^,*;q=0.7"
--header="Keep-Alive: 115"
--header="Connection: keep-alive"
--header="X-Requested-With: XMLHttpRequest"
--header="X-Prototype-Version: 1.5.0_pre0"
--header="Content-Type: application/x-www-form-urlencoded; charset=UTF-8"
--header="Referer: http://XXXXXXXX.ne.jp/11111111111111111111111
--header="Content-Length: 0"
--header="Cookie: b=AAAAAAAA; __utma=BBBBBBBB; __utmz=CCCCCCCC; __utma=DDDDDDDD; __utmz=EEEEEEEE; __utmb=FFFFFFFF; __utmc=GGGGGGGG; __utmb=HHHHHHHH; __utmc=IIIIIIII"
--header="Pragma: no-cache"
--header="Cache-Control: no-cache" http://XXXXXXXX.ne.jp/11111111111111111111111

気になるモノ




Joel Spolsky、青木 靖

価格: ¥ 3,129
価格は記載時点のものです。購入前にAmazonでご確認ください。



wgetでcookieを使用する --load-cookies-sqliteオプションだと!?

wgetcookieを使用するには、以下のオプションを使用する。

 --load-cookies=FILE     load cookies from FILE before session.


Firefox 3.X の場合は、SQLiteのDBでの管理になってるのではそのままでは使用できない。
SQLiteから情報を抜き出して、テキスト形式に擦る必要がある。

Firefoxのオプションで確認して、自力で書きだす

「ツール」 > 「オプション 」
「プライバシー」タブの「Cookieを個別に削除」をクリックして、Cookieの管理画面を出す

Cookeieの名前と内容ををテキストファイルに書き出す。


Firefoxのアドオンで抽出する

SQLiteコマンドで抽出する

sqlite3 -separator ' ' cookies.sqlite 'select * from moz_cookies' > cookies.txt

スクリプトで抽出する


と、GNU Wget 1.10.2のオプションを見ながら書いていたのだが、
GNU Wget 1.11.4 から、 --load-cookies-sqlite、--save-cookies-sqlite
Firefox 3.X のSQLiteの形式も使えるようになってたの??
http://www.mail-archive.com/wget@sunsite.dk/msg11184.html

My work is based on the latest 1.11.4 version. Now use --load-cookies-sqlite
and --save-cookies-sqlite to load/save cookies in Firefox 3.x format.

GNU Wget 1.11.4 ってもう3年前じゃないか( ̄▽ ̄;)


さっそく、GNU Wget 1.11.4をダウンロード
Wget for Windows


libssl32.dllが必要と怒られたので、こちらもダウンロード
OpenSSL for Windows


あれ??そんあオプションねーよ ( ̄△ ̄;)

GNU Wget 1.11.4, a non-interactive network retriever.
Usage: wget [OPTION]... [URL]...

Mandatory arguments to long options are mandatory for short options too.

Startup:
  -V,  --version           display the version of Wget and exit.
  -h,  --help              print this help.
  -b,  --background        go to background after startup.
  -e,  --execute=COMMAND   execute a `.wgetrc'-style command.

Logging and input file:
  -o,  --output-file=FILE    log messages to FILE.
  -a,  --append-output=FILE  append messages to FILE.
  -d,  --debug               print lots of debugging information.
  -q,  --quiet               quiet (no output).
  -v,  --verbose             be verbose (this is the default).
  -nv, --no-verbose          turn off verboseness, without being quiet.
  -i,  --input-file=FILE     download URLs found in FILE.
  -F,  --force-html          treat input file as HTML.
  -B,  --base=URL            prepends URL to relative links in -F -i file.

Download:
  -t,  --tries=NUMBER            set number of retries to NUMBER (0 unlimits).
       --retry-connrefused       retry even if connection is refused.
  -O,  --output-document=FILE    write documents to FILE.
  -nc, --no-clobber              skip downloads that would download to
                                 existing files.
  -c,  --continue                resume getting a partially-downloaded file.
       --progress=TYPE           select progress gauge type.
  -N,  --timestamping            don't re-retrieve files unless newer than
                                 local.
  -S,  --server-response         print server response.
       --spider                  don't download anything.
  -T,  --timeout=SECONDS         set all timeout values to SECONDS.
       --dns-timeout=SECS        set the DNS lookup timeout to SECS.
       --connect-timeout=SECS    set the connect timeout to SECS.
       --read-timeout=SECS       set the read timeout to SECS.
  -w,  --wait=SECONDS            wait SECONDS between retrievals.
       --waitretry=SECONDS       wait 1..SECONDS between retries of a retrieval.
       --random-wait             wait from 0...2*WAIT secs between retrievals.
       --no-proxy                explicitly turn off proxy.
  -Q,  --quota=NUMBER            set retrieval quota to NUMBER.
       --bind-address=ADDRESS    bind to ADDRESS (hostname or IP) on local host.
       --limit-rate=RATE         limit download rate to RATE.
       --no-dns-cache            disable caching DNS lookups.
       --restrict-file-names=OS  restrict chars in file names to ones OS allows.
       --ignore-case             ignore case when matching files/directories.
  -4,  --inet4-only              connect only to IPv4 addresses.
  -6,  --inet6-only              connect only to IPv6 addresses.
       --prefer-family=FAMILY    connect first to addresses of specified family,
                                 one of IPv6, IPv4, or none.
       --user=USER               set both ftp and http user to USER.
       --password=PASS           set both ftp and http password to PASS.

Directories:
  -nd, --no-directories           don't create directories.
  -x,  --force-directories        force creation of directories.
  -nH, --no-host-directories      don't create host directories.
       --protocol-directories     use protocol name in directories.
  -P,  --directory-prefix=PREFIX  save files to PREFIX/...
       --cut-dirs=NUMBER          ignore NUMBER remote directory components.

HTTP options:
       --http-user=USER        set http user to USER.
       --http-password=PASS    set http password to PASS.
       --no-cache              disallow server-cached data.
  -E,  --html-extension        save HTML documents with `.html' extension.
       --ignore-length         ignore `Content-Length' header field.
       --header=STRING         insert STRING among the headers.
       --max-redirect          maximum redirections allowed per page.
       --proxy-user=USER       set USER as proxy username.
       --proxy-password=PASS   set PASS as proxy password.
       --referer=URL           include `Referer: URL' header in HTTP request.
       --save-headers          save the HTTP headers to file.
  -U,  --user-agent=AGENT      identify as AGENT instead of Wget/VERSION.
       --no-http-keep-alive    disable HTTP keep-alive (persistent connections).
       --no-cookies            don't use cookies.
       --load-cookies=FILE     load cookies from FILE before session.
       --save-cookies=FILE     save cookies to FILE after session.
       --keep-session-cookies  load and save session (non-permanent) cookies.
       --post-data=STRING      use the POST method; send STRING as the data.
       --post-file=FILE        use the POST method; send contents of FILE.
       --content-disposition   honor the Content-Disposition header when
                               choosing local file names (EXPERIMENTAL).
       --auth-no-challenge     Send Basic HTTP authentication information
                               without first waiting for the server's
                               challenge.

HTTPS (SSL/TLS) options:
       --secure-protocol=PR     choose secure protocol, one of auto, SSLv2,
                                SSLv3, and TLSv1.
       --no-check-certificate   don't validate the server's certificate.
       --certificate=FILE       client certificate file.
       --certificate-type=TYPE  client certificate type, PEM or DER.
       --private-key=FILE       private key file.
       --private-key-type=TYPE  private key type, PEM or DER.
       --ca-certificate=FILE    file with the bundle of CA's.
       --ca-directory=DIR       directory where hash list of CA's is stored.
       --random-file=FILE       file with random data for seeding the SSL PRNG.
       --egd-file=FILE          file naming the EGD socket with random data.

FTP options:
       --ftp-user=USER         set ftp user to USER.
       --ftp-password=PASS     set ftp password to PASS.
       --no-remove-listing     don't remove `.listing' files.
       --no-glob               turn off FTP file name globbing.
       --no-passive-ftp        disable the "passive" transfer mode.
       --retr-symlinks         when recursing, get linked-to files (not dir).
       --preserve-permissions  preserve remote file permissions.

Recursive download:
  -r,  --recursive          specify recursive download.
  -l,  --level=NUMBER       maximum recursion depth (inf or 0 for infinite).
       --delete-after       delete files locally after downloading them.
  -k,  --convert-links      make links in downloaded HTML point to local files.
  -K,  --backup-converted   before converting file X, back up as X.orig.
  -m,  --mirror             shortcut for -N -r -l inf --no-remove-listing.
  -p,  --page-requisites    get all images, etc. needed to display HTML page.
       --strict-comments    turn on strict (SGML) handling of HTML comments.

Recursive accept/reject:
  -A,  --accept=LIST               comma-separated list of accepted extensions.
  -R,  --reject=LIST               comma-separated list of rejected extensions.
  -D,  --domains=LIST              comma-separated list of accepted domains.
       --exclude-domains=LIST      comma-separated list of rejected domains.
       --follow-ftp                follow FTP links from HTML documents.
       --follow-tags=LIST          comma-separated list of followed HTML tags.
       --ignore-tags=LIST          comma-separated list of ignored HTML tags.
  -H,  --span-hosts                go to foreign hosts when recursive.
  -L,  --relative                  follow relative links only.
  -I,  --include-directories=LIST  list of allowed directories.
  -X,  --exclude-directories=LIST  list of excluded directories.
  -np, --no-parent                 don't ascend to the parent directory.

Mail bug reports and suggestions to <bug-wget@gnu.org>.


Windowsだから? GNU Wget 1.11.4だとまだ?


LinuxCentOS)でGNU Wget 1.12試してみる

[oc@centos5 PKG]$ wget http://ftp.gnu.org/gnu/wget/wget-1.12.tar.gz

tar zxvfで解凍、configure、makeでコンパイルまでで、インストールはせず。

[oc@centos5 src]$ ./wget --help
GNU Wget 1.12, a non-interactive network retriever.
Usage: wget [OPTION]... [URL]...

Mandatory arguments to long options are mandatory for short options too.

Startup:
  -V,  --version           display the version of Wget and exit.
  -h,  --help              print this help.
  -b,  --background        go to background after startup.
  -e,  --execute=COMMAND   execute a `.wgetrc'-style command.

Logging and input file:
  -o,  --output-file=FILE    log messages to FILE.
  -a,  --append-output=FILE  append messages to FILE.
  -d,  --debug               print lots of debugging information.
  -q,  --quiet               quiet (no output).
  -v,  --verbose             be verbose (this is the default).
  -nv, --no-verbose          turn off verboseness, without being quiet.
  -i,  --input-file=FILE     download URLs found in local or external FILE.
  -F,  --force-html          treat input file as HTML.
  -B,  --base=URL            resolves HTML input-file links (-i -F)
                             relative to URL.

Download:
  -t,  --tries=NUMBER            set number of retries to NUMBER (0 unlimits).
       --retry-connrefused       retry even if connection is refused.
  -O,  --output-document=FILE    write documents to FILE.
  -nc, --no-clobber              skip downloads that would download to
                                 existing files.
  -c,  --continue                resume getting a partially-downloaded file.
       --progress=TYPE           select progress gauge type.
  -N,  --timestamping            don't re-retrieve files unless newer than
                                 local.
  -S,  --server-response         print server response.
       --spider                  don't download anything.
  -T,  --timeout=SECONDS         set all timeout values to SECONDS.
       --dns-timeout=SECS        set the DNS lookup timeout to SECS.
       --connect-timeout=SECS    set the connect timeout to SECS.
       --read-timeout=SECS       set the read timeout to SECS.
  -w,  --wait=SECONDS            wait SECONDS between retrievals.
       --waitretry=SECONDS       wait 1..SECONDS between retries of a retrieval.
       --random-wait             wait from 0...2*WAIT secs between retrievals.
       --no-proxy                explicitly turn off proxy.
  -Q,  --quota=NUMBER            set retrieval quota to NUMBER.
       --bind-address=ADDRESS    bind to ADDRESS (hostname or IP) on local host.
       --limit-rate=RATE         limit download rate to RATE.
       --no-dns-cache            disable caching DNS lookups.
       --restrict-file-names=OS  restrict chars in file names to ones OS allows.
       --ignore-case             ignore case when matching files/directories.
  -4,  --inet4-only              connect only to IPv4 addresses.
  -6,  --inet6-only              connect only to IPv6 addresses.
       --prefer-family=FAMILY    connect first to addresses of specified family,
                                 one of IPv6, IPv4, or none.
       --user=USER               set both ftp and http user to USER.
       --password=PASS           set both ftp and http password to PASS.
       --ask-password            prompt for passwords.
       --no-iri                  turn off IRI support.
       --local-encoding=ENC      use ENC as the local encoding for IRIs.
       --remote-encoding=ENC     use ENC as the default remote encoding.

Directories:
  -nd, --no-directories           don't create directories.
  -x,  --force-directories        force creation of directories.
  -nH, --no-host-directories      don't create host directories.
       --protocol-directories     use protocol name in directories.
  -P,  --directory-prefix=PREFIX  save files to PREFIX/...
       --cut-dirs=NUMBER          ignore NUMBER remote directory components.

HTTP options:
       --http-user=USER        set http user to USER.
       --http-password=PASS    set http password to PASS.
       --no-cache              disallow server-cached data.
       --default-page=NAME     Change the default page name (normally
                               this is `index.html'.).
  -E,  --adjust-extension      save HTML/CSS documents with proper extensions.
       --ignore-length         ignore `Content-Length' header field.
       --header=STRING         insert STRING among the headers.
       --max-redirect          maximum redirections allowed per page.
       --proxy-user=USER       set USER as proxy username.
       --proxy-password=PASS   set PASS as proxy password.
       --referer=URL           include `Referer: URL' header in HTTP request.
       --save-headers          save the HTTP headers to file.
  -U,  --user-agent=AGENT      identify as AGENT instead of Wget/VERSION.
       --no-http-keep-alive    disable HTTP keep-alive (persistent connections).
       --no-cookies            don't use cookies.
       --load-cookies=FILE     load cookies from FILE before session.
       --save-cookies=FILE     save cookies to FILE after session.
       --keep-session-cookies  load and save session (non-permanent) cookies.
       --post-data=STRING      use the POST method; send STRING as the data.
       --post-file=FILE        use the POST method; send contents of FILE.
       --content-disposition   honor the Content-Disposition header when
                               choosing local file names (EXPERIMENTAL).
       --auth-no-challenge     send Basic HTTP authentication information
                               without first waiting for the server's
                               challenge.

HTTPS (SSL/TLS) options:
       --secure-protocol=PR     choose secure protocol, one of auto, SSLv2,
                                SSLv3, and TLSv1.
       --no-check-certificate   don't validate the server's certificate.
       --certificate=FILE       client certificate file.
       --certificate-type=TYPE  client certificate type, PEM or DER.
       --private-key=FILE       private key file.
       --private-key-type=TYPE  private key type, PEM or DER.
       --ca-certificate=FILE    file with the bundle of CA's.
       --ca-directory=DIR       directory where hash list of CA's is stored.
       --random-file=FILE       file with random data for seeding the SSL PRNG.
       --egd-file=FILE          file naming the EGD socket with random data.

FTP options:
       --ftp-user=USER         set ftp user to USER.
       --ftp-password=PASS     set ftp password to PASS.
       --no-remove-listing     don't remove `.listing' files.
       --no-glob               turn off FTP file name globbing.
       --no-passive-ftp        disable the "passive" transfer mode.
       --retr-symlinks         when recursing, get linked-to files (not dir).

Recursive download:
  -r,  --recursive          specify recursive download.
  -l,  --level=NUMBER       maximum recursion depth (inf or 0 for infinite).
       --delete-after       delete files locally after downloading them.
  -k,  --convert-links      make links in downloaded HTML or CSS point to
                            local files.
  -K,  --backup-converted   before converting file X, back up as X.orig.
  -m,  --mirror             shortcut for -N -r -l inf --no-remove-listing.
  -p,  --page-requisites    get all images, etc. needed to display HTML page.
       --strict-comments    turn on strict (SGML) handling of HTML comments.

Recursive accept/reject:
  -A,  --accept=LIST               comma-separated list of accepted extensions.
  -R,  --reject=LIST               comma-separated list of rejected extensions.
  -D,  --domains=LIST              comma-separated list of accepted domains.
       --exclude-domains=LIST      comma-separated list of rejected domains.
       --follow-ftp                follow FTP links from HTML documents.
       --follow-tags=LIST          comma-separated list of followed HTML tags.
       --ignore-tags=LIST          comma-separated list of ignored HTML tags.
  -H,  --span-hosts                go to foreign hosts when recursive.
  -L,  --relative                  follow relative links only.
  -I,  --include-directories=LIST  list of allowed directories.
  -X,  --exclude-directories=LIST  list of excluded directories.
  -np, --no-parent                 don't ascend to the parent directory.

Mail bug reports and suggestions to <bug-wget@gnu.org>.

ねーじゃん。

追記 20:48








気になるモノ




北 研二、津田 和彦、獅々堀 正幹

価格: ¥ 3,570
価格は記載時点のものです。購入前にAmazonでご確認ください。



【お題】環境変数からファイル名や拡張子を自由に取り出す方法


バッチファイルでファイルパスからファイル名や拡張子を自由に取り出す方法

ふか 2011/02/02 13:21
これって引数ではない普通の環境変数ではできませんか?

お題もらいました。
バッチファイル、コマンドプロンプト環境変数を展開したいとな。




「%~修飾子引数」だから、素直にやろうとすると、ドライブ文字だけに展開するならこうだよな。

c:\>echo %~dWINDIR%
%~dWINDIR%

c:\>echo %~d%WINDIR%
%~dC:\WINDOWS

両方だめだ。




あれこれ順番を入れ替えてみる

c:\>echo %WINDIR~d%
%WINDIR~d%


c:\>echo %WINDIR%~d
C:\WINDOWS~d


c:\>echo %WINDIR%%~d
C:\WINDOWS%~d

全部ダメ


set /?に載ってる置換で試す

c:\>echo %WINDIR:~d%
%WINDIR:~d%


c:\>echo %WINDIR:~d%WINDIR%%
%WINDIR:~dC:\WINDOWS%


c:\>echo %WINDIR:~d%%
%WINDIR:~d%%

ダメやね。




( ̄~ ̄;) ウーン
for文を使ったこの方法しか思いつかんな。

c:\>for /F %i IN  ('echo %WINDIR%') DO echo %~di

c:\>echo C:
C:

これなら、環境変数を引数にして渡したほうが楽かな。


スマートな方法をご存じの方教えてください。


バッチを吐き出すなんて方法もありか。

@set temp_cmd=%~dp0temp.cmd
@echo @set result=%%~d1 >"%temp_cmd%"
@call "%temp_cmd%" %WINDIR%
@del "%temp_cmd%"
@echo %result%

気になるモノ




ドナルド・A. ノーマン、野島 久雄、D.A. ノーマン

価格: ¥ 3,465
価格は記載時点のものです。購入前にAmazonでご確認ください。



シェルを指定できるタブ型コマンドプロンプトConsole + nyacusを試してみた


今、ckw + nyaousを使っている、5つぐらいckwを立ち上げるときもある。
そのときは、ckwもタブ型だったらなと思うことがある。
FirefoxThunderbird秀丸など、だいぶ前からタブ型が主流で、それに慣れてしまったせいだろう。


Google RSSリーダーでよさそうなソフトが目に止まった。
ckw + nyaosからConsole2 + nyaosに乗り換え

http://sourceforge.net/projects/console/

タブ型コンソール。シェルは最近お気に入りのnayosを設定。

console.exeを起動して、Edit->SettingsでShellにnyaosのexeを指定する。

Cygwinはあんまり入れようと思わない。

シェルを指定できるタブ型コマンドプロンプト console。これは知らなかった。
Cygwinを入れないのは僕も同じ。
僕は、ckw + nyacusを使ってる。(nyacusではなくて、nyaousというのもあるのだろうか?)


追記
nyaousじゃなくて、NYAOSかな?
NYAOS.ORG
以下のように名前が統一されたようだ。

   2.x                                     3.x
NYADOS - DOS,Windows9x用       ----+
PNG NYACUS - Windows2000,XP用  ----+-----  NYAOS
NYAOS/2 - OS/2用               ----+


consoleを試してみる。
海外のソフトウェアだと日本語の表示、入力が気になるところ。



ダウンロード

http://sourceforge.net/projects/console/
Console-2.00b147-Beta_32bit.zip


まだ、ベータなのか。

インストール

Console-2.00b147-Beta_32bit.zipを解凍

  • cosole2\
    • Console.exe
    • ConsoleHook.dll
    • FreeImage.dll
    • FreeImagePlus.dll
    • console.chm
    • console.xml


インストーラはないのでく、そのままコピーすればよさそうだ。

起動

console.exeをダブルクリック

タブ作成

メニューから作成

ボタンから作成

右クリックから作成

タブが作成される

どの手段でも同じようにタブが作成される。



日本語を試す

細かい設定の前に、一番気になる日本語周りを試す

日本語ディレクト

日本語ディレクトリに移動、表示


cdで移動して、Enterを連続実行
文字化けはしないが、プロンプトの表示がおかしくなる。


日本語ファイル

日本語ファイルの表示


同じく文字化けはしないが、表示される位置がおかしい。



シェルの変更

nyacusに期待して、設定変更

1)Edit>settingsからConsole Settingsを開く


2)nyacus.exeをシェルに設定する
  Console 
     Shell:C:\usr\bin\nyacus.exe

日本語を試す

改めて、日本語ディレクトリ、日本語ファイルを試す。

日本語ディレクト

日本語ファイル




ダメだ。
文字化けするわけではないので、全く使い物にならないわけではない。
かつclsで一旦クリアーすれば直る
だが、それを毎回するのは面倒だ。




残念ながら今回の採用については、見送らせて頂きたいと存じます。




やはり ckw + nyaousだな。

あと、GNU utilities for Win32もあれば、いいだろう。

気になるモノ




杉山 貴章、木本 裕紀

価格: ¥ 2,919
価格は記載時点のものです。購入前にAmazonでご確認ください。



バッチファイル/コマンドプロンプトで環境変数が設定されているかをチェックする方法




環境変数が設定されているかをチェックする方法
2パターンを紹介する。

IF文を使う

構文
IF DEFINED 変数 コマンド

DEFINED 条件は EXISTS と同様に動作しますが、環境変数名を受け取って、環境
変数が定義されている場合は真を返します。

環境変数が設定されてたら、コマンドを実行する

C:\>if DEFINED ENV echo OK

C:\>if DEFINED windir echo OK
OK


IF DEFINEDは、コマンド拡張機能に依存する。
デフォルト値では、コマンド拡張機能は有効だが
無効にすることもできる。
環境に依存しないでチェックするには以下のようにすればよい。



検索する方法

構文
set |findstr ^環境変数名= >nul 2>nul
if NOT {%ERRORLEVEL%} == {0} コマンド

環境変数が設定されてなかった、コマンドを実行する
「設定されていたら」の条件にしたい場合は、NOTを
削除すればいい。

C:\>set |findstr ^ENV= >nul 2>nul

C:\>if NOT {%ERRORLEVEL%} == {0} echo ENV not defined
ENV not defined

C:\>set |findstr ^windir= >nul 2>nul

C:\>if NOT {%ERRORLEVEL%} == {0} echo windir not defined

C:\>

こんな方法があったのか! Windows用GNUコマンド群 「GNU utilities for Win32」


MOONGIFTでWindows用のGNUのコマンド群が紹介されていた。
シンプルなWindows用Linuxコマンド集「Gow」


No Command, No Life.
でも僕はCygwinは好きではない。


Gowは知らなかったので、僕が使ってるのは、GNU utilities for Win32というもの。
zip形式での配布なので、インストーラもないので、PATHも設定しないし、Command Prompt Hereに
追加なんて気の利いたものもない。


コマンドはGNUのコマンドが揃えられるが、コマンドプロンプト自体が不便。
GNU utilities for Win32にはbin\sh.exeが入ってるが、文字化けしたりする。
なので、♪UnixのようでUnixでない DOSのようでDOSでない
書いているckwとnyacusを使うのがオススメ。
(Command Prompt Hereなんてレジストリにちょろちょろっと書けばいいわけだし。)


ただ、Gowと違ってGNU utilities for Win32の方は更新が止まっててコマンドの
バージョンが古いかも。

GNU utilities for Win32の入ってるこコマンドは以下の119個

  • 構成
    UnxUtils
      ├─bin
      └─usr
          └─local
              ├─include
              ├─lib
              ├─share
              └─wbin
  • bin
    sh.exe
  • usr\local\wbin
    agrep.exe
    ansi2knr.exe
    basename.exe
    bc.exe
    bison.exe
    bunzip2.exe
    bzip2.exe
    bzip2recover.exe
    cat.exe
    chgrp.exe
    chmod.exe
    chown.exe
    cksum.exe
    cmp.exe
    comm.exe
    compress.exe
    cp.exe
    csplit.exe
    cut.exe
    date.exe
    dc.exe
    dd.exe
    df.exe
    diff.exe
    diff3.exe
    dircolors.exe
    dirname.exe
    du.exe
    echo.exe
    egrep.exe
    env.exe
    expand.exe
    expr.exe
    factor.exe
    fgrep.exe
    find.exe
    flex.exe
    fmt.exe
    fold.exe
    fsplit.exe
    gawk.exe
    gclip.exe
    gplay.exe
    grep.exe
    gsar.exe
    gunzip.exe
    gzip.exe
    head.exe
    id.exe
    indent.exe
    install.exe
    join.exe
    jwhois.exe
    less.exe
    lesskey.exe
    ln.exe
    logname.exe
    ls.exe
    m4.exe
    make.exe
    makedepend.exe
    makemsg.exe
    man.exe
    md5sum.exe
    mkdir.exe
    mkfifo.exe
    mknod.exe
    mv.exe
    mvdir.exe
    nl.exe
    od.exe
    paste.exe
    patch.exe
    pathchk.exe
    pclip.exe
    pr.exe
    printenv.exe
    printf.exe
    pwd.exe
    recode.exe
    rm.exe
    rman.exe
    rmdir.exe
    sdiff.exe
    sed.exe
    seq.exe
    shar.exe
    sleep.exe
    sort.exe
    split.exe
    stego.exe
    su.exe
    sum.exe
    sync.exe
    tac.exe
    tail.exe
    tar.exe
    tee.exe
    test.exe
    touch.exe
    tr.exe
    type.exe
    uname.exe
    unexpand.exe
    uniq.exe
    unrar.exe
    unshar.exe
    unzip.exe
    uudecode.exe
    uuencode.exe
    wc.exe
    wget.exe
    which.exe
    whoami.exe
    xargs.exe
    yes.exe
    zcat.exe
    zip.exe


Happy Command Life






関連あるかもしれない記事

Windowsのエラーメッセージの内容を通訳して"日本語で表示する"ツール(コマンド版)

『ErrMsg』はWindowsのエラーメッセージの内容を通訳してくれるツールというのがあったが、
同じようなコマンドを自作していた。日本語で表示できるし、入力は10進数でも16進数でもOKにしている。

ダウンロード先

http://bit.ly/ckaMqS

使い方

  err2msg エラー番号

実行例

[D:\workspace\C_SandBox\02Windows\err2msg]err2msg 2
ERROR:2
MESSAGE:指定されたファイルが見つかりません。

[D:\workspace\C_SandBox\02Windows\err2msg]err2msg 0x1779
ERROR:6009
MESSAGE:指定されたファイルは読み取り専用です。

[D:\workspace\C_SandBox\02Windows\err2msg]err2msg 0
ERROR:0
MESSAGE:この操作を正しく終了しました。

[D:\workspace\C_SandBox\02Windows\err2msg]err2msg 11111
ERROR:11111
MESSAGE:NULL

ソース

自分のためのコマンドなので手抜き。
err2msg.c

#include <stdlib.h>
#include <stdio.h>
#include <windows.h>

int main(int argc, char* argv[]){

    LPVOID lpMsgBuf = NULL;
    long error = 0;
    char buf[128] = {0};

    if(2 != argc ){
        printf("usage: %s ErrorNumber(GetLastError)\n", argv[0]);
        return (1);
    }
    error = atol(argv[1]);
    if( error == 0 ) {
        error = _strtoui64(argv[1], NULL, 16);
    } 
    FormatMessage(
            FORMAT_MESSAGE_ALLOCATE_BUFFER | 
            FORMAT_MESSAGE_FROM_SYSTEM | 
            FORMAT_MESSAGE_IGNORE_INSERTS,
            NULL,
            error,
            MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
            (LPTSTR) &lpMsgBuf,
            0,
            NULL);
    if(lpMsgBuf == NULL){
        lpMsgBuf = "NULL";
    }
    printf("ERROR:%d\nMESSAGE:%s", error, lpMsgBuf);
}

コンパイル方法

cl err2msg.c