store data into variable in a batch file

Hi,

How can i store the output of a command into a variable and use it at the subsequence statement in a batch file.

For example
I want capture the current date, store in a variable and compare the variable with a date from an input file

Thanks

chee68Asked:
Who is Participating?

[Webinar] Streamline your web hosting managementRegister Today

x
 
cookreConnect With a Mentor Commented:
Another common technique is to create a temporary bat file whose name matches the first word generated by the command in question and whose body extracts a particular parameter from the command line.  You then redirect the output of the desired command to another temporary bat file which you then execute. E.g., for capturing the date:

echo set TODAY=%%5 >the.bat
date <crlf.dat >thing.bat
call thing
del the.bat
del thing.bat

crlf.dat is one of those files you always have around for responding to prompts (just like you also have no.dat and yes.dat).

Note that you can avoid the redirected input by using the /t option on DATE.  In that case, however, the output starts with the three letter day name, so you'd have to create sun.bat, mon.bat, etc., and the date would be in %2.
0
 
Jason_SCommented:
Using KIX scripting (www.kixtart.org) you can accomplish this all in one script file.
0
 
chee68Author Commented:
If there any solution for win2k batch commands?
0
Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

 
cookreCommented:
Sure can.  There are several ways to skin that cat, here's one (along with quite a few other NT/2K nuggets):

http://www.seanet.com/~shardy/ntscript.html#datefaq
0
 
cookreCommented:
0
 
chee68Author Commented:
If there any solution for win2k batch commands?
0
 
cookreCommented:
Yes, those should all work under 2k.
0
All Courses

From novice to tech pro — start learning today.