cmd command and batch processing

Source: Internet
Author: User
Tags goto

1. A cmd command execution result or status value is stored in the variable:%errorlevel%

Most command 0 represents normal, its acquisition and judgment:

If "%errorlevel%" = = "0" Echo executed successfully! Or if errorlevel 0 echo executed successfully!

2. Symbolic:&& and | |

&& and | | Are all connection commands that execute commands sequentially, the first of which is the command that follows when the previous command executes normally, and the latter, of course, is performed when it is not normal.

cmd1&&cmd2| | CMD3:CMD1 performs normally, executes CMD2, and executes CMD3 if the preceding command performs abnormally.

3. Echo and command execution letter output

When the Echo on/off:cmd command executes, the command content is not to be returned, and the batch is usually echo off;

Command output: After the command can indicate the information output location, such as file, 1 is normal output, 2 is the error message.

1>nul does not display normal output

2>nul does not display error output

4. cmd command to start Bat:start

Attached: Bat batch File Small example, for trial run groping learning (the directory involved need to create first).

rem--notes

BAT Code

@ECHO off

REM Set Host Path

SET host_home=c:windowssystem32driversetc

ECHO.

ECHO.

ECHO.

ECHO.

ECHO.

ECHO.

ECHO. =-=-=-=-=87, 151, and 204 environment switching =-=-=-=-=

Echo 1, switch to 87 development environment

Echo 2, switch to 151UAT environment

Echo 3, switch to 204 packaged environment

echo 0, exit

: Restart

ECHO.

set/p cho= Please enter your choice (number):

if/i "%cho%" = = "1" goto EVN87

if/i "%cho%" = = "2" goto EVN151

if/i "%cho%" = = "3" goto EVN204

if/i "%cho%" = = "0" goto End_flag

echo your input is incorrect, please re-enter

REM &&pause&&cls&&goto Statart

Goto restart

: EVN87

REM Update current environment for 87 environment configuration

@xcopy. 87spdbedw.pm%auto_home%bin/s/i/y >> run.log

@xcopy. 87logon_dw_crsusr%auto_home%etc/s/i/y >> run.log

@xcopy. 87hosts%host_home%/s/i/y >> run.log

Echo successfully cut to: 87 development environment!

Goto restart

: EVN151

REM Update current environment for 151 environment configuration

@xcopy. 151spdbedw.pm%auto_home%bin/s/i/y >> run.log

@xcopy. 151logon_dw_crsusr%auto_home%etc/s/i/y >> run.log

@xcopy. 151hosts%host_home%/s/i/y >> run.log

Echo successfully cut to: 151UAT environment!

Goto restart

: EVN204

REM Set PIP server

REM WMIC environment where "name= ' pip_server1 ' and Username= '" "Set variablevalue=" 10.112.9.204 "1>nul

REM WMIC environment where "name= ' pip_server2 ' and Username= '" "Set variablevalue=" 10.112.9.204 "1>nul

REM WMIC environment where "name= ' Pip_server3 ' and Username= '" "Set variablevalue=" 10.112.9.204 "1>nul

REM WMIC environment where "name= ' pip_server4 ' and Username= '" "Set variablevalue=" 10.112.9.204 "1>nul

REM Update current environment for PKG environment configuration

@xcopy. 204spdbedw.pm%auto_home%bin/s/i/y >> run.log

@xcopy. 204logon_dw_crsusr%auto_home%etc/s/i/y >> run.log

@xcopy. 204hosts%host_home%/s/i/y >> run.log

Echo successfully cut to: PKG packaged environment!

Goto restart

: End_flag

Echo's over, thank you!

Pause

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.