We help IT Professionals succeed at work.
Get Started

NT4 DOS Batch: Cant get echo pipe findstr to work

gouranga
gouranga asked
on
1,867 Views
Last Modified: 2007-12-19
I have a batchfile that I've modified from an earlier question.
The batch does an FTP then checks for 5## error codes in the FTP output, this is great unless there's a file that happens to be 5###..  bytes in size as this is also caught as a error:

525 File Not Found
5000 bytes downloaded

The checking part of the script does a ECHO %VAR:~0,3%|FINDSTR /L "5[0-9][0-9]"
So I changed it to:
ECHO %VAR:~0,4%|FINDSTR /L "5[0-9][0-9] "

But it doesn't work!!  The only change is the 0,3 to 0,4 (and a space at the end of the findstr) but it doesn't like it and it says "|" was unexpected!  It works on the command line, but not in the batch!

Heres the code:
FTP -i -n -s:%temp%\ftpscr.dat > c:\temp\ftseftp.out

del %temp%\ftpscr.dat

:: ---------ERROR-CHECKING---------
FOR /f "TOKENS=*" %%i IN (c:\temp\ftseftp.out) DO (set JON=%%i&call :proclog)

IF %ERRCOUNT% GTR 0 (ECHO Error on transmission of files! >> c:\temp\ftseftp.out) ELSE (
echo OK
)
echo ErrorCount is %ERRCOUNT%
set errorlevel=%ERRCOUNT%
GOTO QUIT

:PROCLOG
ECHO %JON:~0,4%|FINDSTR /L "5[0-9][0-9] "
IF NOT ERRORLEVEL 1 (SET /A ERRCOUNT=%ERRCOUNT% + 1)

GOTO :EOF
:: ---------ERROR-CHECKING---------

:QUIT
if  %ERRORLEVEL% == 0 goto :end
echo FAILED
call c:\false.exe
:end
Comment
Watch Question
Commented:
This problem has been solved!
Unlock 1 Answer and 5 Comments.
See Answer
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE