16

したがって、cmd.exe から有効なプログラムを実行して %errorlevel% をチェックすると、0 が返されることを経験から知っています。

C:\>dir logo.bmp
 Volume in drive C has no label.
 Volume Serial Number is 5283-A7A2

 Directory of C:\

05/22/2008  12:43 PM         1,440,054 logo.bmp
               1 File(s)      1,440,054 bytes
               0 Dir(s)  71,723,995,136 bytes free

C:\>echo %errorlevel%
0

同様に、存在しないコマンドを実行しようとして %errorcode% をチェックすると、9009 が表示されます。

C:\>idontexist.exe
'idontexist.exe' is not recognized as an internal or external command,
operable program or batch file.

C:\>echo %errorlevel%
9009

私は何年もバッチ スクリプトを書いてきましたが、常にこのように動作していました。ただし、誰かがこの手法の互換性 (前方および後方の両方) について質問しており、ファイルまたはプログラムが見つからない場合に 9009 をエラーレベルとして実際に定義している Microsoft の公式ドキュメントを見つけることができません。最も近いのはこのサイト ( http://msdn.microsoft.com/en-us/library/ms681381(v=vs.85).aspx ) で、残念ながら 9009 が DNS エラーとしてリストされています。

この動作がマイクロソフトによって文書化されている場所を知っている人はいますか?

4

1 に答える 1

19

Microsoft には、エラー コード (便利な HRESULT を含む) を変換するCommon Error Lookup Toolがあります。9009 の出力は次のとおりです。

# for decimal 9009 / hex 0x2331 :
  MSG_DIR_BAD_COMMAND_OR_FILE                                   cmdmsg.h       
# '%1' is not recognized as an internal or external command,
# operable program or batch file.
  SQL_9009_severity_10                                          sql_err        
# Cannot shrink log file %d (%s) because of minimum log space
# required.
  DNS_ERROR_RCODE_NOTAUTH                                       winerror.h     
# DNS server not authoritative for zone.
# for hex 0x9009 / decimal 36873 :
  SSLEVENT_NO_CIPHERS_SUPPORTED                                 lsapmsgs.mc    
# No suitable default server credential exists on this
# system. This will prevent
# server applications that expect to make use of the system
# default credentials
# from accepting SSL connections. An example of such an
# application is the directory
# server. Applications that manage their own credentials,
# such as the internet
# information server, are not affected by this.
# 4 matches found for "9009"

...つまり、探しているのは cmdmsg.h です。

それ自体は実際にはドキュメントではありませんが、少なくとも公式です。

于 2014-04-15T21:44:55.283 に答える