バッチ プログラムのラベル付き行に cmd.exe を転送します。 バッチ・プログラム内では、このコマンドは、ラベルによって識別される行にコマンド処理を送ります。 ラベルが見つかると、次の行から始まるコマンドから処理が続行されます。
Syntax
goto <label>
Parameters
Parameter | Description |
---|---|
<label> |
バッチ プログラムでラベルとして使用されるテキスト文字列を指定します。 |
/? | コマンド プロンプトにヘルプを表示します。 |
Remarks
If command extensions are enabled (the default), and you use the goto command with a target label of :EOF, you transfer control to the end of the current batch script file and exit the batch script file without defining a label. When you use this command with the :EOF label, you must insert a colon before the label. (例:
goto:EOF
)。You can use spaces in the label parameter, but you can't include other separators (for example, semicolons (;) or equal signs (=)).
The label value that you specify must match a label in the batch program. バッチ・プログラム内のラベルはコロン (:)で始まる必要があります。 行がコロンで始まる場合、ラベルとして扱われ、その行のコマンドは無視されます。 If your batch program doesn't contain the label that you specify in the label parameter, then the batch program stops and displays the following message:
Label not found
.You can use goto with other commands to perform conditional operations. For more information about using goto for conditional operations, see the if command.
Examples
次のバッチ プログラムは、ドライブ A のディスクをシステム ディスクとしてフォーマットします。 If the operation is successful, the goto command directs processing to the :end label:
echo off
format a: /s
if not errorlevel 1 goto end
echo An error occurred during formatting.
:end
echo End of batch program.