Monday, August 26, 2013

Batch File - Output Command to Variable

I am by no means an expert in batch scripting and if you follow my posts you will have noticed I'm more of a VB scripting man.  However I was doing some batch scripting for a customer of mine today in which I need to export some data from a command line executable tool to a variable.

This can be done as follows:

FOR /F "delims=" %i IN ('date /t') DO set today=%i
echo %today%

Now one thing which caught me out,  if you put this code into a batch script "as is" you will notice the script will error out.  This is because to declare variables in a batch script you must use two % signs instead of one.

For example, "set today=%I" needs to be "set today=%%i".  To put the code in a batch script and to make it run you would use:

FOR /F "delims=" %%i IN ('date /t') DO set today=%%i
echo %today%

I hope this small post has been helpful - thankyou for reading.

1 comment:

  1. I am going to can quickly declare of which follow can make among the better pursuit different watches available might pursue to converse a small amount of regarding these people. During the last a number of years by means of amazing steadiness, the enjoy includes unveiled a couple of brand new hobby designer watches offering a fantastic layout, helpful not to mention useful challenging routines, masculine variations, not to mention fair charges. This current year which will aggregate from attributes finds out per se inside the reduced variant watch. It all may resemble a wristwatch has got released before so it uses an existing action along with very similar name because alternative styles. The things you happen to be looking at is often a refinement when it comes to dial design and style plus entire speech contained in the large and already favored assortment of game products. What holds that gallery together along with good sized sizes and additionally military-inspired seems to be may be the top. The application has developed in a different as a result of screw-down caps on you just perspective them from a single section to another. Bright signs or symptoms means that that must be locked though pink signals would mean that it must be start intended for rotating and / or to be pulled away. The dial of the enjoy can be quite familiarized to make sure you group followers. There are some a little various cure, though the collection bank hands and fingers in addition to 12 o'clock an hour sign are available and in one piece. It will be simultaneously legible along with assertive throughout sort of white technique. The case might be further water repellent so that you can 100 metres and also charcoal wrist strap is normally calfskin imitation leather with an very nearly fabric look for the software. I are unsure the reason why this observe insists at timepieces for this mother nature currently being restricted release brands. They are never for one festivity and also trigger and in fact represent brand new know-how. We can sole view these people to be a approve that whilst the see game different watches will be fantastic, they have been no key perhaps the brand on the whole product sales plan. As a consequence, they are just minimal through creation in any case to may possibly also manufacture them constrained variant pieces. As an alternative, many people merely tend not to like to invest in types having prolonged development periods in addition to providing simply a limited number facilitates a designs to always be a great deal more manageable. Since a resurrection through earlier nineties, the actual watch contains become among the many world most interesting and the majority of innovative producers, a situation it does not suffer a loss of, without regard to the correct way fiscal crises or ever-changing movements have an effect on a. For the reason that grandiose when of which looks, all the view has often showed slightly more laid-back end with the advertise, continuing to be always observe through tranquil and built-up novelties, taking in front typically the brand name and its most famous libraries by an individual tiny factor at the same time. However at times you will find several small-scale part that will should be prepared, and the enjoy tells united states the fact that brand is usually picking up typically the schedule.