batch-file-es Windows

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

HELLO!John Smith!(Suponiendo que escribiste John Smith como tu nombre).Ahora la consola de su archivo por lotes se ve así:what is your name?John Smithdone!Press any key to continue...HELLO!John Smith!(y debería salir tan rápido que es posible que no pueda ver nada después de la solicitud. Pressany key to coninue... )Redirigir el carácter especial con la expansión retrasada habilitada¡Este ejemplo hace eco del carácter especial ! en un archivo. Esto solo funcionaría cuandoDelayedExpansion esté deshabilitado. Cuando la expansión retrasada está habilitada, deberáutilizar tres caracteres y un signo de exclamación como este:@echo offsetlocal enabledelayedexpansionecho ^^^!>fileecho ^>>>filegoto :eof^> is the text>> is the redirect operatorpauseendlocalexit /bEste código hará eco del siguiente texto en el archivo.!>como^^^ escapes the ! and echos it into the file^> escapes the > and echos it into the fileEscribir en un archivo@echo offhttps://riptutorial.com/es/home 75

clsecho Please input the file path, surrounded by "double quotation marks" if necessary.REM If you don't want to redirect, escape the > by preceding it with ^set /p filepath=^>echo Writing a random numberecho %RANDOM% > %filepath%echo Reading the random numbertype %filepath%REM Successive file writes will overwrite the previous file contentsecho Writing the current directory tree:> %filepath% tree /Aecho Reading the filetype %filepath%REM nul is a special file. It is always empty, no matter what you write to it.echo Writing to nultype %windir%\win.ini > nulecho Reading from nultype nulecho Writing nul's contents to the filetype nul > %filepath%echo Reading the filetype %filepath%Lea Redirección de entrada y salida. en línea: https://riptutorial.com/es/batchfile/topic/7502/redireccion-de-entrada-y-salida-https://riptutorial.com/es/home 76

HELLO!

John Smith!

(Suponiendo que escribiste John Smith como tu nombre).

Ahora la consola de su archivo por lotes se ve así:

what is your name?John Smith

done!

Press any key to continue...

HELLO!

John Smith!

(y debería salir tan rápido que es posible que no pueda ver nada después de la solicitud. Press

any key to coninue... )

Redirigir el carácter especial con la expansión retrasada habilitada

¡Este ejemplo hace eco del carácter especial ! en un archivo. Esto solo funcionaría cuando

DelayedExpansion esté deshabilitado. Cuando la expansión retrasada está habilitada, deberá

utilizar tres caracteres y un signo de exclamación como este:

@echo off

setlocal enabledelayedexpansion

echo ^^^!>file

echo ^>>>file

goto :eof

^> is the text

>> is the redirect operator

pause

endlocal

exit /b

Este código hará eco del siguiente texto en el archivo.

!

>

como

^^^ escapes the ! and echos it into the file

^> escapes the > and echos it into the file

Escribir en un archivo

@echo off

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

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

Saved successfully!

Ooh no, something went wrong!