batch-file-es Windows

carlos.wilber.franco
from carlos.wilber.franco More from this publisher
08.02.2022 Views

(example.bat is going to contain "message > file1.bat")Lo mismo ocurre con otras cosas en loteEl siguiente paso requiere que usted tenga algún conocimiento sobre las variables y lasdeclaraciones:Haga clic aquí para conocer las variables | Haga clic aquí para obtener más informaciónsobre las declaraciones if y else.Variables:SET example="text"ECHO %example% > file.bat(This will output "text" to file.bat)si no queremos que se muestre "texto", sino simplemente% example% luego escriba:ECHO ^%example^% > file.bat(This will output "%example%" to file.bat)Declaraciones IF / ELSE:ELSE statements are written with "pipes" ||IF ^%example^%=="Hello" ECHO True || ECHO False > file.bat(example.bat is going to contain "if %example%=="Hello" echo True")[it ignores everything after the ELSE statement]para dar salida a toda la línea, entonces hacemos lo mismo que antes.IF ^%example^%=="Hello" ECHO True ^|^| ECHO False > file.batThis will output:IF %example%=="Hello" ECHO True || ECHO FalseSi la variable es igual a "Hola", entonces dirá "Verdadero", ELSE dirá "Falso"Guardando la salida de muchos comandosUsando muchos comandos ECHO para crear un archivo por lotes:(echo echo hi, this is the date todayecho date /Techo echo created on %DATE%echo pause >nul)>hi.bathttps://riptutorial.com/es/home 25

El intérprete de comandos trata toda la sección entre paréntesis como un solo comando, luegoguarda toda la salida en hi.bat .hi.bat ahora contiene:echo hi, this is the date todaydate /Techo created on [date created]pause >nulLea Creando archivos usando Batch en línea: https://riptutorial.com/es/batchfile/topic/7129/creando-archivos-usando-batchhttps://riptutorial.com/es/home 26

(example.bat is going to contain "message > file1.bat")

Lo mismo ocurre con otras cosas en lote

El siguiente paso requiere que usted tenga algún conocimiento sobre las variables y las

declaraciones:

Haga clic aquí para conocer las variables | Haga clic aquí para obtener más información

sobre las declaraciones if y else.

Variables:

SET example="text"

ECHO %example% > file.bat

(This will output "text" to file.bat)

si no queremos que se muestre "texto", sino simplemente% example% luego escriba:

ECHO ^%example^% > file.bat

(This will output "%example%" to file.bat)

Declaraciones IF / ELSE:

ELSE statements are written with "pipes" ||

IF ^%example^%=="Hello" ECHO True || ECHO False > file.bat

(example.bat is going to contain "if %example%=="Hello" echo True")

[it ignores everything after the ELSE statement]

para dar salida a toda la línea, entonces hacemos lo mismo que antes.

IF ^%example^%=="Hello" ECHO True ^|^| ECHO False > file.bat

This will output:

IF %example%=="Hello" ECHO True || ECHO False

Si la variable es igual a "Hola", entonces dirá "Verdadero", ELSE dirá "Falso"

Guardando la salida de muchos comandos

Usando muchos comandos ECHO para crear un archivo por lotes:

(

echo echo hi, this is the date today

echo date /T

echo echo created on %DATE%

echo pause >nul

)>hi.bat

https://riptutorial.com/es/home 25

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!