Several common commands of window bat script


Window bat script

Control statement

  • if
  • for
  • set

Basic identification

Comment command

  • rem
  • :: symbol


  • Echo off / on off or show echo


  • @Putting the character before the command turns off echo of the command

Parameter usage

%I represents the parameters in the batch file

  • %0 for batch itself, full path with extension

How to prompt users for variables

The following variable is a variable name

  • Set / P variable prompt user for input
  • %Variable% means to get the value of the variable

Jump command


  • Before executing goto, define a valid label, that is, the location of goto


Start calls external programs in batch processing.

  • External program runs asynchronously, batch processing continues to execute
  • Note: the environment variable information of the process pulled by start is the same as that of bat. If you want to use the latest system environment variable, you need to refresh it with a script

Call command calls other bat programs

  • Must have. Bat or. CMD extension
  • Internal subroutines can be called, starting with: Label

Pipeline command “|” | “

“|” executes multiple commands at the same time, and does not execute the latter command after encountering the correct one

“|” uses the result of the first command as a parameter of the second command

Combined command


Execute command (s), whether successful or not


Execute multiple commands at the same time, and stop executing subsequent commands in case of execution error

Redirection command >, > >

  • “>
  • “>

Other symbols

  • “” double quotes allow spaces in strings
  • , comma equivalent to space
  • ; used to isolate different target parameters when the commands are the same

-() can include multiple lines of commands