1.

Solve : Batch to read from file?

Answer»

On another project I am working on, I am looking for a way to READ a ascii text file say Token.TXT and pass that ascii data read in ENTIRETY until EOF to a VARIABLE to be tested.

The Token.TXT file would have either PASS or FAILURE in it, and I need my batch to read the ASCII and pass it to a variable, then an IF statement and ELSE statement. So if the ASCII equals FAILURE then trigger the Failure event, otherwise anything else read in, which would only be PASS would go back to Passed at the beginning of the batch and run in a loop.

Such as:

(*** Somehow pass the read in ascii from Token.TXT to variable VARIABLE ) "Dont know how to do this"

REM Then perform the following test of the ASCII and goto Failure or Passed

IF VARIABLE = "FAILURE" {
goto Failure
}

ELSE {
goto Passed
}

Going to use this for testing services. The services condition causes a PASS or FAILURE Token.TXT file to be written to a folder. The batch that I am WRITING will once a minute run a loop to test the ASCII text in the Token.TXT file.

Thanks for your help in advance!!!

Dave

Not sure which of your machines you're planning on using this:

Code: [Select]@echo off
for /f "tokens=1-2*" %%i in (token.txt) do (
if %%i==PASS (goto pass) else (goto FAIL)
)

You could also use find or findstr, using the errorlevel to determine which logic to execute.

Code: [Select]find /i "pass" token.txt
if errorlevel 1 goto fail
if errorlevel 0 goto pass

As your requirements become more complex, you'll find that batch code lacks the functionality you need. 8-)

Thanks again Sidewinder [smiley=thumbsup.gif] that works.

I was thinking it was going to be more complex with having to define to read to EOF. And have to pass a string value to a variable then compare. But this works very well. You are definately a master of batch programming.

Thanks for your help!!!



Discussion

No Comment Found