Solved

store data into variable in a batch file

Posted on 2002-03-28
7
636 Views
Last Modified: 2008-03-17
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
Comment
Question by:chee68
  • 4
  • 2
7 Comments
 
LVL 5

Expert Comment

by:Jason_S
ID: 6903227
Using KIX scripting (www.kixtart.org) you can accomplish this all in one script file.
0
 

Author Comment

by:chee68
ID: 6904078
If there any solution for win2k batch commands?
0
 
LVL 22

Expert Comment

by:cookre
ID: 6904179
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
What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

 
LVL 22

Expert Comment

by:cookre
ID: 6904193
0
 
LVL 22

Accepted Solution

by:
cookre earned 100 total points
ID: 6904217
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
 

Author Comment

by:chee68
ID: 6904301
If there any solution for win2k batch commands?
0
 
LVL 22

Expert Comment

by:cookre
ID: 6904377
Yes, those should all work under 2k.
0

Featured Post

Get up to 2TB FREE CLOUD per backup license!

An exclusive Black Friday offer just for Expert Exchange audience! Buy any of our top-rated backup solutions & get up to 2TB free cloud per system! Perform local & cloud backup in the same step, and restore instantly—anytime, anywhere. Grab this deal now before it disappears!

Join & Write a Comment

NTFS file system has been developed by Microsoft that is widely used by Windows NT operating system and its advanced versions. It is the mostly used over FAT file system as it provides superior features like reliability, security, storage, efficienc…
In this article, I show you step by step with screenshots to assist you - HOW TO: Deploy and Install the VMware vCenter Server Appliance 6.5 (VCSA 6.5), with some helpful tips along the way.
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…
In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're interested in additional methods for monitoring bandwidt…

743 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now