Celebrate National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

store data into variable in a batch file

Posted on 2002-03-28
7
Medium Priority
?
648 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Does Your Cloud Backup Use Blockchain Technology?

Blockchain technology has already revolutionized finance thanks to Bitcoin. Now it's disrupting other areas, including the realm of data protection. Learn how blockchain is now being used to authenticate backup files and keep them safe from hackers.

 
LVL 22

Expert Comment

by:cookre
ID: 6904193
0
 
LVL 22

Accepted Solution

by:
cookre earned 300 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

Complete VMware vSphere® ESX(i) & Hyper-V Backup

Capture your entire system, including the host, with patented disk imaging integrated with VMware VADP / Microsoft VSS and RCT. RTOs is as low as 15 seconds with Acronis Active Restore™. You can enjoy unlimited P2V/V2V migrations from any source (even from a different hypervisor)

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

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…
Without even knowing it, most of us are using web applications on a daily basis.  In fact, Gmail and Yahoo email, Twitter, Facebook, and eBay are used by most of us daily—and they are web applications. We generally confuse these web applications to…
This is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…

730 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