EV: DOS batch commands

echo .

echo "my comments"

echo %windir%   显示windows variables/环境变量

type readme.txt
 
copy con/IO
-------------------------
copy con output.txt Copy from Console to ...
After you type this command and press ENTER, MS-DOS copies everything you type to the file OUTPUT.TXT. When you are finished typing, press CTRL+Z to indicate that you want to end the file. The Control-Z character will appear on the screen as " ^Z ". You can also end a COPY CON command by pressing the F6 key. Pressing F6 also generates the Control-Z character; a "^Z" still appears on the screen.
copy con lpt1 Copies information from the keyboard to a printer connected to LPT1
 
wait/delay/pause
---------------------------
pause
timeout /t 10
 
error handle/handling
---------------------------------------

call Batch1.bat
if %ERRORLEVEL% NEQ 0 goto failed
echo ...Completed Batch1, %ERRORLEVEL%

call Batch2.bat
if %ERRORLEVEL% NEQ 0 goto failed
echo ...Completed Batch2, %ERRORLEVEL%

Call Batch3.bat
if %ERRORLEVEL% NEQ 0 goto failed
echo ...Completed Batch3, %ERRORLEVEL%

goto end

:failed
echo ....ERROR Please check logs for further details, %ERRORLEVEL%

:end
endlocal

========================================
------------startsql.bat-------------
@echo off

if ""%1"" == """" goto startsql
echo Waiting for %1 seconds...
sleep %1

:startsql
echo Starting sql server service...
net start MSSQL$SQL2012

pause

------------end of startsql.bat-------------

========================================

REM

In a batch file REM at the start of a line signifies a comment or REMARK, alternatively adding :: at the start of a line has a similar effect.

For example:

@ECHO OFF
::
:: First comment

REM Second comment
REM

Echo Hello REM This remark is displayed by echo
Echo Hello & REM This remark is ignored by echo

Copy work.xls backup.xls &:: We backed up the file

Although you can use Rem without a comment to add vertical spacing to a batch file, you can also use completely blank lines. The blank lines are ignored when processing the batch program.

The double-colon is not documented as a comment command, it is a special case of a label that acts as a comment.

An alternative approach is to use plain text and a goto command to jump execution past the comments:

@Echo OFF
Goto :START
Description can go here
which can even include - | > characters

:START
 ---------------------------------------
 

posted on 2013-12-27 09:49  weihongji  阅读(243)  评论(0编辑  收藏  举报

导航