|
Answer» Hello again,
Now I am going to perform checking of users' input about the file(test.txt) and gives ADVISE for user inputs.
Again the test.txt consists of 3 lines: IP username= password= ATTACH NODE !
Users are required to change the content and here is an example:- IP 10.1.1.1 username=abcd password=00000 ATTACH Node "Test" !
However, if user forgot to input the required field, that is if the file content still consists of < character, it will display message that advise user to input the corresponding field
such as: - for , it will display a message to tell user to input IP address.
- for username=, it will display a message to tell user to input username.
- for password= it will display a message to tell user to input password.
- for ATTACH Node , it will display a message to tell user to input node_name
I think I have to use FOR function but which token and delimiter do I need to used? Also please teach me how to test for the present of character < and >
Thanks, ThomasAs checked out from other screens, I found the solution as shown. Just want to share with OTHERS for interest. Please FEEL free to comment.
========================================== @ECHO OFF REM FINDSTR ^< test.txt > nul IF %errorlevel%==0 GOTO syntaxERR REM FINDSTR ^> test.txt > nul IF %errorlevel%==0 GOTO syntaxERR REM :syntaxERR ECHO ****************** syntaxERR *********************** ECHO. ECHO Some parameter^(s^) in test.txt cannot parse! ECHO. ECHO Please check the content of test.txt. goto end REM REM FOR /f "tokens=3*" %%a IN (test.txt) DO SET sysname=%%a %%b REM FINDSTR IP test.txt > temp_line1.txt FOR /f "tokens=2,4,6 delims== " %%c IN (temp_line1.txt) DO ( SET ip=%%c SET user=%%d SET PASS=%%e ) IF EXIST "temp_line1.txt". (DEL/q "temp_line1.txt" > nul.) REM ECHO. ECHO Current settings in test.txt: - ECHO. ECHO IP %ip% ECHO username=%user% ECHO password=%pass% ECHO ATTACH Node %sysname% ECHO. ECHO Please verify REM :end pause exit ================================================
|