For comprehensive info, see a free book. Set a variable: SET FOO='bar' Use a variable: echo%FOO% Command line arguments are variables:%1,%2 etc. Check if a variable is defined: IF NOT DEFINED FOO SET FOO='bar'. Useful for testing command line arguments. Check a result code from the last executed command: IF ERRORLEVEL $n $CMD-TO-EXECUTE. It executes the command if result code is equal or greater to $n, so to check for any failures use 1. Do things in a loop: FOR /L%%A IN (1,1,10) DO @echo hello Execute another script: call another.bat Check if directory exists: IF EXIST e: directory GOTO USE_E Here’s an example of a batch file that does a few common things: @ECHO OFF @rem 'pushd $dir ' puts $dir on directory stack pushd. SET COMMENT =%1 IF NOT DEFINED COMMENT SET COMMENT = ' SET FOO = 'bar' IF%FOO% == 'bar' goto IS_BAR echo The above should always be true goto END:IS_BAR nmake -f Makefile.vc IF ERRORLEVEL 1 goto ERR_ONE_OR_HIGHER echo Compilation successful! Goto END:ERR_ONE_OR_HIGHER echo Compilation failed! The following example illustrates the use of the PATH environment variable within a batch file: @ECHO The PATH environment variable was detected. @ECHO The PATH environment variable was NOT detected. Sunderkand in hindi pdf. PATH=C: DOS; This example tests for the existence of the PATH variable. Goto END:END @rem popd pops the directory name from the stack and does cd there popd For comprehensive info, see a free book. Southside nexus xp.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |