Why this code says echo is off?

前端 未结 5 1846
灰色年华
灰色年华 2021-02-05 01:46

What is wrong with this code? It says ECHO is off.

@ECHO off
set /p pattern=Enter id:
findstr %pattern% .\\a.txt > result
if %errorlevel%==0 (
se         


        
5条回答
  •  滥情空心
    2021-02-05 02:17

    enter image description hereFirst create a file a.txt in the same directory u have this batch file ... write some text in that...Note: only Windows 2000 Windows ME Windows XP Windows Vista Windows 7 supports FINDSTR

    set /p pattern=Enter id:
    findstr %pattern% a.txt > __query.tmp
    set /p result=<__query.tmp
    if %errorlevel%==0 (
    set var2= %result%
    echo %var2%
    set var1= %var2:~5,3%
    echo %var1% > test.txt
    echo %var1%
    ) else (
    echo error
    )
    del __query.tmp
    pause
    

    run this bath file .. you will find a substring(start=5,length=3) of the first line of string you have in a.txt in a newly created file test.txt. Finally got it working !

提交回复
热议问题