〜雑食系SEの作業履歴〜
2011-01-27
Robocopyの戻り値を知りたい
ファイルのコピーやフォルダの同期などのバッチファイルを以前まではXcopyコマンドを利用して作成していたのですが、
どうやらWindows2008ではXcopyではなく、Robocopyの使用を推奨しているようです。
Windows2003でのXcopy /?の実行結果
Windows2008でのXcopy /?の実行結果
そこでRobocopyを使用してバッチファイルを作成し始めたのですが、Robocopyの終了コードが良く分かりませんでした。
JP1などのジョブ管理ツールなどから実行すると、デフォルトの設定ではリターンコードが0以外が返ってくるとエラーとなります。
Robocopyで作成したバッチファイルが成功したり、失敗したりが続いたので調べることに。
Webで調べるとリソースキッドの中にドキュメントがあるとのことなので、以下のURLからリソースキッドをダウンロードしました。
リソースキッドをインストールすると、インストールフォルダにrobocopy.docというMS WORDのファイルがあります。
その中にReturn Codeに関する表がありました。
| Hex Bit Value | Decimal Value | Meaning If Set |
| 0x10 | 16 | Serious error. Robocopy did not copy any files. This is either a usage error or an error due to insufficient access privileges on the source or destination directories. |
| 0x08 | 8 | Some files or directories could not be copied (copy errors occurred and the retry limit was exceeded). Check these errors further. |
| 0x04 | 4 | Some Mismatched files or directories were detected. Examine the output log. Housekeeping is probably necessary. |
| 0x02 | 2 | Some Extra files or directories were detected. Examine the output log. Some housekeeping may be needed. |
| 0x01 | 1 | One or more files were copied successfully (that is, new files have arrived). |
| 0x00 | 0 | No errors occurred, and no copying was done. The source and destination directory trees are completely synchronized. |
上の表によると、コピーが正常に終了した場合は1が返ってくるようですね。。。
もう少し細かい判定をしたければ…ということで、以下のような判定用のバッチも記載されていましたので、貼っておきます。
if errorlevel 16 echo ***FATAL ERROR*** & goto end if errorlevel 15 echo FAIL MISM XTRA COPY & goto end if errorlevel 14 echo FAIL MISM XTRA & goto end if errorlevel 13 echo FAIL MISM COPY & goto end if errorlevel 12 echo FAIL MISM & goto end if errorlevel 11 echo FAIL XTRA COPY & goto end if errorlevel 10 echo FAIL XTRA & goto end if errorlevel 9 echo FAIL COPY & goto end if errorlevel 8 echo FAIL & goto end if errorlevel 7 echo MISM XTRA COPY & goto end if errorlevel 6 echo MISM XTRA & goto end if errorlevel 5 echo MISM COPY & goto end if errorlevel 4 echo MISM & goto end if errorlevel 3 echo XTRA COPY & goto end if errorlevel 2 echo XTRA & goto end if errorlevel 1 echo COPY & goto end if errorlevel 0 echo --no change-- & goto end :end
なるほど。。。
トラックバック - http://d.hatena.ne.jp/sikakura/20110127/1296102650
リンク元
- 88 http://pipes.yahoo.com/pipes/pipe.info?_id=242f50e5030d8e9e73ce52013bcbf820
- 24 http://www.google.co.jp/search?sourceid=navclient&hl=ja&ie=UTF-8&rlz=1T4SKPT_jaJP402JP402&q=イントラマート メニュー 遅い
- 14 http://www.google.co.jp/search?hl=ja&lr=lang_ja&tbs=lr:lang_1ja&q=oracle11g+java+データ型+マッピング&aq=f&aqi=&aql=&oq=
- 8 http://www.google.co.jp/search?hl=ja&client=firefox-a&rls=org.mozilla:ja:official&q=hudson+ジョブ+同期&aq=f&aqi=&aql=&oq=
- 8 http://www.google.co.jp/search?q=バッチ 実行 ユーザ 指定&hl=ja&prmd=ivnsfd&ei=LPRATZfEF8aPcayAubwO&start=10&sa=N
- 7 http://www.google.co.jp/search?hl=ja&source=hp&q=バッチ実行+実行ユーザ指定&btnG=Google+検索&lr=lang_ja&aq=o&aqi=&aql=&oq=
- 5 http://www.google.co.jp/search?q=管理者権限+バッチファイル&hl=ja&prmd=ivns&ei=nPpATeq5D4q8uwPL3s3OAw&start=10&sa=N
- 5 http://www.google.co.jp/search?sourceid=chrome&ie=UTF-8&q=izpack
- 4 http://www.google.co.jp/hws/search?hl=ja&q=管理者として実行&client=fenrir&adsafe=off&safe=off&lr=lang_ja
- 3 http://search.yahoo.co.jp/search?p=タスク バッチファイル 管理者権限で実行&aq=-1&oq=&ei=UTF-8&fr=top_ga1_sa&x=wrt