Sorry for warming up this thread.
A similar problem as initially posted here arose for me, when I wanted to run a string extraction in a FOR loop:
neither
Code: Select all
CALL SET "flash_drive=%%flash_drives:~%offset%,2%%"
nor
Code: Select all
CALL SET "flash_drive=%%flash_drives:~!offset!,2%%"
works, CMD.exe crashes. I can't read the screen content, because it closes too fast.
Here the code excerpt where the code line is embedded:
Code: Select all
@ECHO OFF
SETLOCAL enableDelayedExpansion
rem a lot of lines of code here
ECHO(
ECHO !"!%TAB%>>> Checking flash drives (SD / USB) for enough capacity ...
SET /p flash_drives=<%found_flash_drives_file%
SET flash_drives=%flash_drives:~0,-1%
rem Content looks like "E: G: I: "
CALL :getStringLength "%flash_drives%"
rem String length must be a real multiple of 3
SET /a "test=%string_length% %% 3"
IF %test% NEQ 0 (
CALL :displayError "FAILED: Checking flash drives (SD / USB) for enough capacity"
GOTO :END
)
FOR /l %%i IN (1,3,%string_length%) DO (
SET /a "offset=%%i-1"
CALL SET "flash_drive=%%flash_drives:~!offset!,2%%" <=== THIS IS CRASHING
CALL :getTotalVolumeSpaceGB "!flash_drive!"
IF %script_error_occurred% EQU 1 (
CALL :displayError "FAILED: getTotalVolumeSpaceGB"
GOTO :END
)
IF %disk_space_total_GB% LSS %disk_space_needed_GB% (
SET "unusable_flash_drives=!unusable_flash_drives!!flash_drive! "
)
)
rem another lot of lines of code here
:END
ENDLOCAL
EXIT /b
Hope you can help me again. TIA