setlocal EnableDelayedExpansion
for /L %%a in (1,1,%NUMBER%) do (
ECHO #define BLE_UUID_!SERVICE_NAME_UC!_!CARACTERISTIC_NAME_UC[%%a]!_CHAR !CARACTERISTIC_UUID[%%a]!
)
凡NUMBER,SERVICE_NAME_UC,CARACTERISTIC_NAME_UC [%% A]和CARACTERISTIC_UUID [%%子程序A]之前已經設置,一切工作正常,我獲得:
#define BLE_UUID_SECURITY_RELAY_CMD_CHAR 0x4800
#define BLE_UUID_SECURITY_RELAY_STATUS_CHAR 0x4801
#define BLE_UUID_SECURITY_CONFIG_CHAR 0x4802
但是,我想喜歡做的事是調用一個子程序裏面的FOR循環,它的任務,如以這樣的方式
setlocal EnableDelayedExpansion
for /L %%a in (1,1,%NUMBER%) do (
CALL :SetOutput_h %INPUT_HEADER_PATH%\DefCharUUID.txt %%a
)
GOTO:EOF
:SetOutput_h
:: Subroutine to insert parts of code in the header output file
:: The argument for this subroutine is the NAME of the code part you want to insert in the output file
SET "PART_NAME_H=%~1"
SET "INDEX=%~2"
(FOR /F "delims=" %%A IN ('findstr /N "^" %PART_NAME_H%') DO (
REM Get the line *including* !variable! replacements
SET "line=%%A"
REM Remove leading number, show the rest *including* empty lines
ECHO(!line:*:=!
)) >> %OUTPUT_H%
GOTO:EOF
凡文件DefCharUUID.txt只包含此:
#define BLE_UUID_!SERVICE_NAME_UC!_!CARACTERISTIC_NAME_UC[%INDEX%]!_CHAR !CARACTERISTIC_UUID[%INDEX%]!
的輸出文件genarated包含此:
#define BLE_UUID_SECURITY__CHAR
因此,具有方括號的部分已被忽略。
我在做什麼錯?
你爲什麼''調用'':SetOutput_h'有兩個參數,其中第一個是完全多餘的循環?如果你在該循環之前只設置了「PART_NAME_H =%INPUT_HEADER_PATH%\ DefCharUUID.txt」,那麼你只需要'CALL:SetOutput_h %% a'和'SET'INDEX =%1「'雖然我也注意到你沒有似乎也在使用'%INDEX%'! – Compo