From Schmid.wiki
Jump to: navigation, search

Comments

Use labels for comments, as REM is an actual command and may impede performance. A double colon can signify a comment to avoid confusion with actual labels:

:: This is a comment
REM This is a comment that requires executing a command

Starting Program from BAT File Without Terminal Window

@start /b \path\to\program argument

Starting BAT Files

Without allowing the BAT file to change the environment or current dir:

cmd /c something.bat

Quietly:

nircmd exec hide something.bat

Built-in Variables

%~dp0   full path of dir containing bat file

Dispatch BAT Arguments

someprogram.exe %1 %2 %3 %4 %5 %6 %7 %8 %9

(so stupid)

Multiple Commands Per Line

Execute two commands, regardless of errors:

echo awe & echo some

Execute first command, and second command if no error:

dir \somewhere >nil 2>&1 && echo \somewhere exists

Execute first command, and second command if error:

dir \somewhere >nil 2>&1 || echo An error occurred

Redirection

Redirect output to hell

C:\>echo svin >nul

Variables

set VARIABLE=value
echo %VARIABLE%

References