• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 670
  • Last Modified:

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

0
chee68
Asked:
chee68
  • 4
  • 2
1 Solution
 
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
 
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
Upgrade your Question Security!

Your question, your audience. Choose who sees your identity—and your question—with question security.

 
cookreCommented:
0
 
cookreCommented:
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
 
chee68Author Commented:
If there any solution for win2k batch commands?
0
 
cookreCommented:
Yes, those should all work under 2k.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 4
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now