Page 1 of 1

How to store a DOS command result in variable & later us

Posted: 24 Jul 2009 19:36
by agarwaldvk
Hi Everybody

This is my first posting in this forum.

I want to be able to store the result of the "Find" dos command in a variable and then later use it to do an if test. Is there a way to do it?

This is what I am trying to do in the batch file :-

The "Test.txt" file has the following contents (result of the find command) :-

Blank Line
---------- CTR1.TXT: 3

I want to be able to store the number "3" (this can range from 1 through to 4 both inclusive) in a variable and then do an "If" test to determine if it is "1" or not. If it is "1" then run another command (say run this file [test.grs - this contains the Genie Backup commands for a scheduled job - I know how to do this bit]

What I am not able to do is to store this number "3" (in this instance) excluding all the other text to to be able to test and compare if that number in the variable is 1 or not?

Any suggestions on that please!


Best regards


Deepak Agarwal

Posted: 27 Jul 2009 15:02
by avery_larry
for /f "tokens=2 delims=:" %%a in (test.txt) do set number=%%a
if %number%==1 (
echo It's 1 so do what you want here.
) else (
echo The number is %number%, not 1.
)

Posted: 27 Jul 2009 16:50
by agarwaldvk
Dear avery_larry

Thanks very much - that was exactly what I wanted.

I am sure this is will do exactly what I wanted to do.


Greatly appreciated.


Best regards


Deepak Agarwal