Getting BAT script

Getting BAT script

  • echo: After the display command character
  • chcp 65001: is replaced by UTF-8 code page
  • echo off: all operational command of this statement are not displayed command-line statement
  • @: Echo off with similar, but it added to the front of each command line, can only affect the current row
  • call: calling another batch file
  • pause: pause after the execution of the batch and displays the prompt Press any key to continue ... and wait for the user to press any key on the screen to continue
  • rem: Comment lines
  • Parameter% [1-9]: parameter is the string when running the batch file after the file name with a space of (or Tab) delimited
  • if goto
  • goto
  • CHOICE:

CHOICE [/C choices] [/N] [/CS] [/T timeout /D choice] [/M text]

Parameter List:
/ C option to specify a list of choices to be created. The default list is "YN".

/ N hides the list of options in the prompt. In front of the prompt message is displayed,
the choices are still enabled.

/ CS option allows you to select case-sensitive. By default, this tool
is case-insensitive.

Before / T timeout to make a choice by default, pause the number of seconds. Acceptable values from 0
to 9999. If you specify 0, there will be no pause, the default option
will be selected.

/ D choice Specifies the default option after nnnn seconds. Character must be called in / C is selected from
a group of options specified; the same time, must / T specified nnnn.

Message / M prior to specify a prompt to display text. If not specified, the tool only
displays a prompt.

/? Displays this help message.

Note:
ERRORLEVEL environment variable is set to select from a set of selected key index. The first listed option
select Back 1, 2 return to the second selection, and the like. If the user presses a key that is not a valid option,
the tool will issue a warning beep. If errors are detected at the tool, it will return 255
ERRORLEVEL value. If the user presses Ctrl + Break or Ctrl + C keys, the tool will return 0
the ERRORLEVEL value. When used in a batch program ERRORLEVEL parameter, the parameter descending
sequence arrangement.

  • For

FOR %%variable IN (set) DO command [command-parameters]

%% variable parameter specifies a single letter replaceable.
(set) to specify one or a group of files. You can use wildcards.
command specified command for each file.
command-parameters
specify parameters for a particular command or command-line switches.

For example there is a line in a batch file:
for %% c in ( .bat .txt) do of the type %% c

The command line will display the contents of all the current directory to bat and txt file extension.

Examples

Based on the above knowledge, you can write a script simple and practical

@echo off
chcp 65001
CHOICE /C 123 /M "1.启动Jenkins;2.清理系统垃圾;3.退出"
if %errorlevel%==1 goto StartJenkins
if %errorlevel%==2 goto clearn 
if %errorlevel%==3 goto end

:StartJenkins
d:
cd D:\apache-tomcat-9.0.21\webapps\Jenkins
java -jar jenkins.war --ajp13Port=-1 --httpPort=8081

:clearn
echo 清理系统垃圾
call C:\Users\Bill\Desktop\清理系统.bat
goto end

:end
echo good bye
PAUSE

Guess you like

Origin www.cnblogs.com/lianstyle/p/11109633.html