gouranga
asked on
NT4 DOS Batch: Cant get echo pipe findstr to work
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
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
ASKER
Sorry, I'm not being clear..
The Script reads the FTP output file line by line:
FOR /f "TOKENS=*" %%i IN (c:\temp\ftseftp.out) DO (set JON=%%i&call :proclog)
Then in the proc proclog it checks the first 3 (or in the non-working modified version 4) characters
ECHO %JON:~0,3% or ECHO %JON:~0,4%
And pipes that to the findstr command that looks for "5##" or "5## "
In the version that echo's the 4 characters the script fails with:
| was unexpected at this time.
Is there a way of turning on more verbose logging?
The Script reads the FTP output file line by line:
FOR /f "TOKENS=*" %%i IN (c:\temp\ftseftp.out) DO (set JON=%%i&call :proclog)
Then in the proc proclog it checks the first 3 (or in the non-working modified version 4) characters
ECHO %JON:~0,3% or ECHO %JON:~0,4%
And pipes that to the findstr command that looks for "5##" or "5## "
In the version that echo's the 4 characters the script fails with:
| was unexpected at this time.
Is there a way of turning on more verbose logging?
ASKER
I've got it through trial and error..
ECHO (%JON:~0,4%)|FINDSTR /L "5[0-9][0-9] "
Putting the echo in brackets protects it from the |
ECHO (%JON:~0,4%)|FINDSTR /L "5[0-9][0-9] "
Putting the echo in brackets protects it from the |
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Oh I see..
Thank you..
Thank you..
525 File Not Found
512 bytes downloaded
And now ?
I would try following :
:PROCLOG
ECHO %JON% | FIND /I "bytes downloaded"
IF NOT ERRORLEVEL 1 GOTO end
ECHO %JON:~0,3%|FINDSTR /L "5[0-9][0-9]"
IF NOT ERRORLEVEL 1 (SET /A ERRCOUNT=%ERRCOUNT% + 1)
GOTO end
if the %JON:~0,3% line still doesn't work then try
FINDSTR /L "5[0-9][0-9]" < ECHO %JON:~0,3%