Solved

store data into variable in a batch file

Posted on 2002-03-28
7
640 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
NAS Cloud Backup Strategies

This article explains backup scenarios when using network storage. We review the so-called “3-2-1 strategy” and summarize the methods you can use to send NAS data to the cloud

 
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

U.S. Department of Agriculture and Acronis Access

With the new era of mobile computing, smartphones and tablets, wireless communications and cloud services, the USDA sought to take advantage of a mobilized workforce and the blurring lines between personal and corporate computing resources.

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…
One of the biggest threats in the cyber realm pertains to advanced persistent threats (APTs). This paper is a compare and contrast of Russian and Chinese APT's.
Windows 10 is mostly good. However the one thing that annoys me is how many clicks you have to do to dial a VPN connection. You have to go to settings from the start menu, (2 clicks), Network and Internet (1 click), Click VPN (another click) then fi…
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…

776 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