Search found 10 matches
- 2023-Nov-10, 5:46 pm
- Forum: Windows CMD Shell
- Topic: The page: echo.html
- Replies: 3
- Views: 1347
Re: The page: echo.html
Thanks, but there is still a flaw on the page. There are some edge cases (such as adding \..\..\..\..\ to a variable) where only ( will work without errors e.g. Echo (%_var% There is a space between "ECHO" and "(", but there shouldn't. Better: ... where only "(" will wo...
- 2023-Nov-10, 5:39 pm
- Forum: Windows CMD Shell
- Topic: the auto exec page
- Replies: 7
- Views: 10625
Re: the auto exec page
Hi Simon, the pipe behaves differently because when a pipe starts the sub processes it uses quite different options for cmd.exe test.bat @echo off setlocal EnableDelayedExpansion echo cmdcmdline=!cmdcmdline! C:\Users\jeb>echo Hello | test.bat cmdcmdline=C:\Windows\system32\cmd.exe /S /D /c" tes...
- 2023-Nov-09, 9:02 am
- Forum: Windows CMD Shell
- Topic: the auto exec page
- Replies: 7
- Views: 10625
Re: the auto exec page
A short example Autorun.bat @echo off setlocal EnableDelayedExpansion set "cmd=!cmdcmdline!" if "%~1" NEQ "" goto :install if "!cmd:~1,-2!" == "!comspec!" ( echo *********** Autorun: %~f0 *********** echo !cmd!# endlocal ) ELSE if "!cmd:~,22!&qu...
- 2023-Nov-06, 11:31 am
- Forum: Windows CMD Shell
- Topic: the auto exec page
- Replies: 7
- Views: 10625
Re: the auto exec page
There could be some info about the behavior of the autostart registry keys. It should be noted, that these are used not only when a new cmd window opens. Also for drag&drop actions to a batch file. It will also be called in FOR /F loops, this can have negative effects to batch files parsing the ...
- 2023-Nov-06, 10:27 am
- Forum: Windows CMD Shell
- Topic: The page: echo.html
- Replies: 3
- Views: 1347
The page: echo.html
Hi Simon, the description on the echo.html can be improved. A more robust alternative is to separate with : instead of a space. ECHO:%_department% This might be more robust, but still not good :-) It fails for set "var=\..\..\..\..\windows\system32\calc.exe" echo:%var% The best and only sa...
- 2023-Aug-23, 8:31 am
- Forum: Windows CMD Shell
- Topic: PUSHD example logic inverted
- Replies: 3
- Views: 7860
Re: PUSHD example logic inverted
You are right, just tested to be absolutely sure.
- 2023-Aug-03, 1:11 pm
- Forum: Windows CMD Shell
- Topic: Local variables not cleaned-up on batch script crash
- Replies: 1
- Views: 7519
Re: Local variables not cleaned-up on batch script crash
Hi Jesus2099, the problem/feature of the missing endlocal on syntax errors is known, see Exit from nested batch file . It can be useful to examine all variables when a batch file crashes. But in your case, you want a clean environment after calling a batch file, even after a syntax error. I suppose,...
- 2023-May-10, 2:17 pm
- Forum: Windows CMD Shell
- Topic: Function to Sanitize User Input
- Replies: 2
- Views: 3947
Re: Function to Sanitize User Input
Nice try, ... but try to get it working with this simple test string :o Set "_example=jeb1: Part1 ^ & Part2 !"^&" & Part3" To avoid the first problem when showing the _example variable, I changed the code a bit REM Replace: Echo Input: %_example% <nul set /p ".=Y...
- 2023-May-10, 2:01 pm
- Forum: Windows CMD Shell
- Topic: Read a file, output each line to a new file, preserve all characters?
- Replies: 8
- Views: 5511
Re: Read a file, output each line to a new file, preserve all characters?
To be bullet proof, you need the delayed toggling technique. @echo off set "filename=%~1" SETLOCAL DisableDelayedExpansion FOR /F "delims=" %%a in ('findstr /n "^" "%filename%"') do ( set "var=%%a" SETLOCAL EnableDelayedExpansion set "var=!var:*...
- 2023-May-10, 1:46 pm
- Forum: Windows CMD Shell
- Topic: "call exit" - Exit batch file from call subroutine
- Replies: 7
- Views: 4986
Re: "call exit" - Exit batch file from call subroutine
Yes it's possible to leave a function or even nested functions. I know three different ways. 1. Syntax Error A syntax error stops immediately a batch file. @echo off call :func1 echo End of main exit /b :func1 echo Start of :func1 call :func2 echo End of :func1 exit /b :func2 echo Start of :func2 ca...