Tom's Guide | Tom's Hardware | Tom's Games
![]() |
![]() |
![]() |
I am using the following command in a batch file
------------------------
for /F "skip=8" %%a IN (E:\tempfile.log | findstr /I ERROR) do (goto :ERR2)
Del E:\tempfile.log /q
--------------
What I need is to skip the 1st 8 lines (using skip=8) in the E:\tempfile.log and then find the word "Error" / ERROR in the 9th line (ALWAYS), and if you find this word, display error message in :ERR2.
But this is never executed, means it doesnt goto :ERR2.
Whats the problem in this command?

[1] XP is not DOS.
[2] I don't see the label :ERR2
[3] If it boils down to: 'check line nine for ERROR', try this:
=========================
:: chk line 9 for ERROR@echo off & setLocal EnableDelayedExpansion
set N=
for /f "tokens=* delims=" %%a in (E:\tempfile.log) do (
set /a N+=1
if !N! equ 9 (
echo %%a | find /i "error" > nul
if !errorlevel! equ 0 echo here's where we GOTO
)
)
=====================================
If at first you don't succeed, you're about average.M2

Mechanix,
Sorry for the goofup....
actually I am trying to get this o/p since last 3 days, so quite exhausted after all this tries.
I will try your solution, and reply back
Thanks,
Ravin

I need to expand my code to search for multiple words and then throw error based on the string found
i.e if the string is "Error" goto :ERR2 or if string is "Missing" goto :ERR3
Mechanix, can we expand your code to handle the above situation?
Thanx,
Ravin

@echo off & setLocal EnableDelayedExpansion
set N=
for /f "tokens=* delims=" %%a in (E:\tempfile.log) do (
set /a N+=1
if !N! equ 9 (
echo %%a | find /i "error" > nul
if !errorlevel! equ 0 echo here's where we GOTO :ERR2
echo %%a | find /i "Missing" > nul
if !errorlevel! equ 0 echo here's where we GOTO :ERR3
)
)
=====================================
If at first you don't succeed, you're about average.M2

Hey Mechanix,
You are a gem of a person.
It works like a charm.
Just one last question.
I am having this command"call windchill wt.load.loadfromfile -d c:\parts.xml > c:\logerror.log"
which may throw errors and logs it in the logfile, in which we are catching words and redirecting to goto :ERRn
but the command above is also getting displayed in my launch cmd also, which I dont want.
Pl help...
Thanx,
Ravin

Most commands send 'regular output' to stdout and errors to stderr.
Usually, writing to stdout and to stderr both 'put it on the screen'.
You can redirect bothe like this:dir aa > dirlist 2> errlog
note: NO SPACE between 2 and >
=====================================
If at first you don't succeed, you're about average.M2

I do not want the following command to be executed on the screen, but the o/p or error of this command only in the logfile
"call windchill wt.load.loadfromfile -d c:\parts.xml > c:\logerror.log".Mechanix, is it possible that we execute this command in a minimized window, redirect o/p (>logfile.log) and exit that window and back to main cmd?
Thanx,
Ravin

Is windchill a batch?
=====================================
If at first you don't succeed, you're about average.M2

Nope windchill is an exe, and then we are passing the parameters to it like
windchill wt.load.loadfromfile -d c:\parts.xml

start /min windchill wt.load.loadfromfile -d c:\parts.xml
=====================================
If at first you don't succeed, you're about average.M2

Hey mechanix,
I am redirecting the output to a log file,e.g.
echo +++Successfull ++++ >> c:\succcess.logbut I want the message to be prepended with a date/time stamp. e.g
04/18/2009 14:20 +++Successfull ++++How do I get the above output?

echo %DATE% %TIME% +++Successfull ++++ >> c:\succcess.log
=====================================
If at first you don't succeed, you're about average.M2

![]() |
Toshiba Sattelite Laptop ...
|
Delete words in a text do...
|
| Login or Register to Reply | |
| Login | Register |
| Ads by Google |