rem - Comment
If you revisit a batch file later or hand it to someone else, leaving comments that explain the intent of each step makes it much easier to read.
The rem command is the official way to write comments in a Windows batch file.
This article explains the basics of rem, its relationship with @echo off and @rem, and how it differs from the commonly seen ::.
Basics of the rem Command
The basic syntax for a comment is:
rem comment
For example:
@echo off
setlocal
rem Ask the user for a favorite fruit
echo Please enter your favorite fruit.
set /p fruit=Example: apple
endlocal
When you run this batch file, the comment stays in the file as an explanation, and the only messages shown on screen are those printed by echo.
Why Comments Sometimes Appear on Screen
rem does not display comments.
Comments sometimes show up on screen because command echo is on, so the line itself is printed.
setlocal
rem Ask the user for a favorite fruit
echo Please enter your favorite fruit.
set /p fruit=Example: apple
endlocal

中小企業経営者のためのRPA入門 RPA導入を成功させる方法

60分でわかる! AIエージェント 超 入門

コマンドラインの黒い画面が怖いんです。

知識・才能ゼロでもらく~に月10万円稼ぐ! よくわかるAI副業超入門
The Difference Between @echo off and @rem
@echo off
Putting @echo off at the top of a file stops the following command lines from being displayed. It is the most common way to start a batch file.
@rem
@rem suppresses command echo for that one line only.
setlocal
@rem Ask the user for a favorite fruit
echo Please enter your favorite fruit.
set /p fruit=Example: apple
endlocal
To hide unnecessary command lines for the whole batch file, put @echo off at the top. Use @rem when you only want to suppress a single line.
Writing a Comment at the End of a Line
rem is treated as a command, so to place it after another command on the same line, join them with &.
echo Starting process & rem start message
Everything after rem, including &, is treated as part of the comment. Commands placed after rem on the same line are not executed.
Is It OK to Use ::?
You will often see :: comment in batch files.
However, :: is not an official comment command. It abuses label syntax, so it can behave unexpectedly inside parenthesized blocks or when combined with redirection.
For maintainability and safety, rem is the safer choice for comments. It is especially recommended for reusable or shared batch files.
Commenting Out Code
Batch files have no official multi-line comment syntax like /* ... */ in C.
To temporarily disable several lines, adding rem to each line is the clearest and safest approach.
rem copy source.txt backup\source.txt
rem move source.txt archived\source.txt
rem echo Done
Character Encoding Pitfalls
rem itself does not cause errors. The usual problem is a mismatch between the batch file’s character encoding and the code page used by cmd.exe.
Batch files that contain Japanese or other non-ASCII comments can show garbled text depending on the environment.
Batch files with non-ASCII text can behave differently depending on the environment, whether saved as UTF-8 or Shift_JIS. Save in the encoding your existing setup uses, and test on the real machine, including chcp 65001 if needed.
Summary
- The official way to write a comment is
rem comment - Comments appear on screen because of command echo, not because
remprints them - Use
@echo offfor the whole file, or@remfor a single line ::is a shortcut;remis safer when robustness matters- With non-ASCII comments, check the combination of file encoding and code page