The SHIFT command only move the numbered arguments %1,%2,...,%9, but has no effect on %* The solution of chatGPT works in this case, because the first argument seems to be a single word. But it's not a general solution, because it fails in the case where the first argument includes a space . myBatch...
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...
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...
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...
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 ...
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...
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,...