http://www.cnblogs.com/pingfan1990/p/4558630.html ThemesMongoDBLinux
such as: Choice/c:dme defrag,mem,end will show defrag , mem,end[d,m,e]?< The contents of the span class= "constant" >sample:sample.bat are as follows: @echo Offchoice/c:dme defrag,mem,endif errorlevel 3 Goto defrag (should first determine the highest error code) if errorlevel 2 Goto mem< span class= "keyword" >if errotlevel 1 goto end: Defragc:\dos\defraggoto end:memmemgoto end:endecho 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.
If command
The IF indicates that the specified conditions will be judged, thus deciding to execute different commands. There are three types of formats:
⒈if "parameter" = = "string" command to execute
If the argument equals the specified string, the condition is set, run the command, or run the next sentence. (note is two equals)
If "%1" = = "A" format a:
if {%1}=={} goto noparms
if {%2}=={} goto noparms
⒉if exist file name to execute command
If there is a specified file, then the condition is established, run the command, otherwise run the next sentence.
such as if exist Config.sys edit Config.sys
⒊if errorlevel/if not errorlevel number pending command
If the return code equals the specified number, the condition is set up, run the command, or run the next sentence.
if errorlevel 2 goto x2
DOS programs will return a number to DOS, called the error code ERRORLEVEL or return code, the common return code is 0, 1.
for command
The for command is a more complex command that is used primarily for parameters that loop through commands within a specified range.
When using the for command in a batch file, specify the variable using the%%variable
for {%variable| %%variable} in (set) do command [CommandLineOptions]
%variable specifies a single-letter replaceable parameter.
(set) specifies one or a set of files. Wildcard characters can be used.
command specifies the commands to execute on each file.
Command-parameters specify parameters or command-line switches for specific commands.
When using the for command in a batch file, specify the variable using the%%variable
And don't use%variable. Variable names are case-sensitive, so%i differs from%i
Third, Bat batch processing example
The role of batch processing
Simply put, the role of batch processing is to automatically execute multiple commands consecutively.
Here is one of the simplest applications: When you start the WPS software, you must do it every time (> The DOS prompt is represented in the previous section):
C:\>CD wps C:\wps>spdos c:\wps>py c:\wps>wbx C:\wps>wps
If you do this once every time you use WPS, do you feel a lot of trouble?
Well, with batch processing, you can implement these cumbersome operations to simplify, first we write a runwps.bat batch file, the content is as follows:
@echo off c:cd\wps spdos py wbx wps cd\
Later, each time we enter WPS, we only need to run runwps this batch file.
D. bat batch Implementation start MongoDB script
MongoDB Install bin path D:\Program files\mongodb\bin,mongodb in Data folder D:\Program Files\mongodb\data
We should be like this in the cmd command window, start the MongoDB database
CD D:\Program files\mongodb\binmongod --depath "D:\Program files\mongodb\data"
But every time we have to knock on these, it really makes us very troublesome, so we can use bat's just to do such a bat file:
:: Indicates that all running commands do not display the command line itself after this statementecho off echo hello:: Enter D disk D:CD \program Files\mongodb\binmongod--dbpath Span class= "string" > "d:\program files\mongodb\data" // The following is the comment section:: Mongod--DBPath "d:\program files\ Mongodb\data ":: d:> echo " this D ":: D:> echo "this D":: d:> echo "this D":: d:> echo "this D ":: Mongod--dbpath " d:\program files\mongodb\data ":: Write B.txt file::d ir D:\Program files\mongodb\bin> b.txt::p ause
Through this file, every time we have to open the MongoDB service, click on the bat file, you can.
Resources:
BAT file http://baike.baidu.com/view/1024624.htm
BAT file Syntax and tricks (BAT file authoring and use)
BAT file syntax and tips for writing and using bat files
Start MongoDB script with bat batch processing