1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

Windowsバッチでよく使う処理一覧

Last updated at Posted at 2022-07-05

はじめに

この記事はWindowsバッチを書く時によく出てくる処理について一覧にしたものです。個人的な備忘録メモですが、皆様のお役にも立てたら嬉しく思います。

処理一覧

コマンド実行時の標準出力をOFFにする

@echo off
echo 明示的なechoは出力されます。

バッチファイルの先頭には必ずつけよう。

バッチファイルの置かれたパスを取得する

rem バッチファイルの置かれたパスを取得する
set BATCH_PATH=%~dp0

現在のパスを取得する

rem 現在のパス取得
cd C:\tmp\mybatch_tmp
set CURRENT_PATH=%CD%

コマンド実行のエラーハンドリング1

git pull
if %errorlevel% neq 0 ( goto ERROR )

:SUCCESS
echo Processing Success.
goto FINAL
:ERROR
echo Processing Error !!
:FINAL
echo Finish BAT Program.

コマンドは何でもよいが、git pullを例にした。

コマンド実行のエラーハンドリング2

call ant "compile" -f build.xml -l compile.log
if %errorlevel% neq 0 ( goto ERROR ) 

コマンドによってはcallをつける必要がある。エラーハンドリングした後の処理は前述の通り。

とりあえず、ここまで。

1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?