DOS : Encodage OEM850 (Langue Europe Occidentale) ==> ci-joint script VB conversion OEM vers ANSI
Autorun sur CMD : [HKLM\SOFTWARE\Microsoft\Command Processor\Autorun]
for /f "tokens=4 delims= " %%i in ('ping www.yahoo.com ^| findstr /i /c:"Statistiques Ping"') do echo %%i
Renvoie dans fichiers de sortie
Renvoie du flux standard vers fichier (remplace le contenu du fichier)
<Command> >out.log
<Command> 1>out.log
Renvoie du flux d'erreur vers fichier (remplace le contenu du fichier)
<Command> 2>out.log
Renvoie du flux standard vers fichier (ajout du contenu au fichier)
<Command> >>out.log
<Command> 1>>out.log
Renvoie du flux d'erreur vers fichier (ajout du contenu au fichier)
<Command> 2>>err.log
Renvoie des deux flux vers fichier
<Command> 1>out.log 2>err.log
<Command> 1>out.log 2>&1
Pipes et renvoi
A | B => Renvoi la sortie de A vers B (pipes)
A & B => Exécute A puis B
A && B => Exécute A puis B seulement si A se termine correctement
A || B => Exécute A puis B seulement si A ne se termine pas correctement
Appel à des functions
call :fun1 param1
echo je reprend ici
:fun1
echo %~1
goto EOF
[...]
:EOF
Appel à des functions en isolant les variables
call :fun1 param1
echo je reprend ici
:fun1
SETLOCAL
echo %~1
ENDLOCAL
goto EOF
[...]
:EOF
Transtyper
Extraire une sous-chaîne
%variable:~deb,taille%
Remplacer un caractère
%variable:a=b%
Copy
Concaténer 2 fichiers
Copy myfile1.txt+myfile2.txt
Copier le texte saisie dans un fichier
Copy con c:\a.txt
Echo en couleur dans batch
echo <ESC>[{format} {Texte} ==> <ESC> = caractère escape soit 0d027
avec {format} = voir image "Code_couleur_echo.jpg" et fichier "Echo couleur.txt"