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

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
agarwaldvk
Posts: 3
Joined: 24 Jul 2009 19:23

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

#1 Post by agarwaldvk » 24 Jul 2009 19:36

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

avery_larry
Expert
Posts: 391
Joined: 19 Mar 2009 08:47
Location: Iowa

#2 Post by avery_larry » 27 Jul 2009 15:02

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.
)

agarwaldvk
Posts: 3
Joined: 24 Jul 2009 19:23

#3 Post by agarwaldvk » 27 Jul 2009 16:50

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

Post Reply