Windows Bat (Batch)--basic syntax
1. @
If you have it at the beginning of the line, the command is not displayed.
2. Echo
2.1 echo [{On|off}] [message]
Output, Echo.
2.2 On | Off
It is actually a switch command, that is, it has only two states: open and close. So there's the echo on and echo off two commands.
(1) Echo off
Show only execution results
(2) echo on (default)
Show execution commands (except echo) and execution results
(3) > Output redirection
Create or empty a file, and then output the data to a file
echo Hi > A.txt
Append data to a file
Echo This is a text "A.txt
echo Hi > A.txt
Type A.txt
Echo This is a text "A.txt
Type A.txt
3. Notes
:: or REM
4. ":" and Goto
(1) Goto
Jump to Tag
(2):
Define a label
Sample:
[Python]
if {%1}=={} goto noparms
if {%2}=={} goto noparms (if,% 1,%2 if you do not understand it, skip it first and there will be a detailed explanation later.) )
@Rem check parameters if NULL show usage
: noparms
echo Usage:monitor.bat ServerIP portnumber
Goto END
5.Pause
When you run the Pause command, the following message is displayed:
[Python]
Press any key to continue ...
Sample:
[Python]
@echo off
: Begin
Echo Pause
Pause
Goto BEGIN
6.Call command
Another batch program is called from one batch program, and the parent batch program is not terminated. The call command accepts the label that is used as the calling target. If you use call outside of a script or batch file, it will not work at the command line.
Grammar
Call [Drive:][path] FileName [Batchparameters] [: Label [arguments]
Parameters
[Drive:} [Path] FileName
Specifies the location and name of the batch program to invoke. The filename parameter must have a. bat or. cmd extension.
7.start command
Calling an external program, all DOS commands and command-line programs can be called by the start command.
Common parameters of intrusion:
Min Start window minimized
Separate start 16-bit Windows programs in separate spaces
High starts the application in the high priority category
REALTIME starting the application in the REALTIME priority category
Wait to start the application and wait for it to end
Parameters these parameters for transmission to the command/program
The application that executes is a 32-bit GUI application when CMD. EXE returns a command prompt without waiting for the application to terminate. If executed within a command script, the new behavior does not occur.
8.choice command
Choice Use this command to let the user enter a character to run different commands. Use should be Plus/C: parameters, C: After the prompt should be written to enter the characters, no spaces between. It has a return code of 1234 ...
such as: Choice/c:dme defrag,mem,end
will display
Defrag,mem,end[d,m,e]?
Sample:
The contents of Sample.bat are as follows:
@echo off
Choice/c:dme Defrag,mem,end
if errorlevel 3 goto defrag (the highest number of error codes should be judged first)
if errorlevel 2 goto MEM
If Errotlevel 1 goto end
:d Efrag
C:dosdefrag
Goto END
: Mem
Mem
Goto END
: End
echo Good bye
When this file runs, Defrag,mem,end[d,m,e] is displayed? The user can select D m e, then the IF statement will be judged, D represents the execution of a program segment labeled Defrag, M represents the execution of a program segment labeled Mem, E represents the execution of a program segment labeled End, and each segment ends with a goto end to jump the program to the end label. Then the program will show good Bye, the end of the file.
9.%x Parameters
%1--1th parameter
%2--2nd parameter
%3--3rd parameter
...
NET use%1ipc$%3/u: "%2"
%1--IP
%2--username
%3--Password