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 1 year has passed since last update.

バッチファイルでpingが無限ループする

Last updated at Posted at 2021-03-30

pingでサーバーとの疎通確認をしたかったので、簡単なバッチを作成。

ping.bat
@echo off
ping 127.0.0.1
if %ERRORLEVEL%==1 (
   echo "ping error"
)
pause
exit

すると何故か以下のように無限ループ…。
ping 127.0.0.1
ping 127.0.0.1
ping 127.0.0.1
ping 127.0.0.1
ping 127.0.0.1
ping 127.0.0.1

なぜこうなるかというと、ファイル名が「ping.bat」となっていたことが原因。
windows標準の設定ではコマンドの優先順位が .bat > .exe となっているため、ひたすら自分自身を参照することになるらしい。

ファイル名とコマンドを同じ名前にするのは避けましょう。

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?