My issue: Read - Write file working fine, but I don't know how to check variable.txt file write completed to execute another task and I want handle this synchronize.
Detail:
File env.txt contains some value
Ex:
value1
value2
When I reading file env.txt line by line, I want replace each this value assign to file variable.txt and execute a task.
Here my code:
Code: Select all
@echo off
setlocal enableextensions enabledelayedexpansion
rem Defined some variables...
for /F "delims=" %%a in (%ENV_FILE_PATH%) do (
set /A count+=1
set "array[!count!]=%%a"
)
set newline=^& echo.
set new_file=
for /L %%i in (1,1,%count%) do (
set replace_host=TESTED_HOST="!array[%%i]!"
FOR /F "usebackq delims=" %%a in (%VARIABLE_FILE_PATH%) do (
set "var=%%a"
echo(!var!|findstr /r /c:"!search!" >nul && (
set "var=!replace_host!"
)
echo(!var!|findstr /r /c:"!search_user_name!" >nul && (
set "var=!default_user_admin!"
)
echo(!var!|findstr /r /c:"!search_pwd!" >nul && (
set "var=!default_pwd_admin!"
)
set new_file=!new_file!%newline%!var!
)
echo(!new_file!) > !FILE_VARIABLE_OUT!
rem ( (call ) >>!FILE_VARIABLE_OUT! ) 2>nul && (
rem Execute task when check file write completed
rem echo The file write completed
rem ) || (
rem echo The file is still being created
rem )
)
endlocal
pause