Solved

Windows batch scripting and variable expansion

Posted on 2002-03-29
3
482 Views
Last Modified: 2013-12-03
I am attempting to set an env variable in the batch script and read in it's expansion from an external file, then print the value.

--batch file -----
set X=Z:

for /f %%i in (line.txt) do @set VAR=%%i

echo %VAR%

--line.txt -----
%X%

--As output -----
I am wanting to see Z: echo to the command window.  With what I have above, it will currently echo %X%, but I need that to expand also.

0
Comment
Question by:mouse050297
  • 2
3 Comments
 
LVL 22

Accepted Solution

by:
cookre earned 100 total points
ID: 6906268
Your problem is that the command interpretor never actually sees what's being read from line.txt as anything other than data, i.e., it doesn't expand %%i beyond the single level.

This sort of thing, however, will get you what you want:

for /f %%i in (line.txt) do (
echo set VAR=%%i >aaa.bat
call aaa.bat
)
del aaa.bat
0
 

Author Comment

by:mouse050297
ID: 6906489
I guess I should have added a little more of what I want to do once the variable is expanded.  I need to expand it within the original batch file.  Calling a secondary batch file is appropriate for my original question and I can reference it accordingly.  Here is what I am trying to do.  I am given the string
$(X)\msdos.sys
I break this into two files, $(X) into line.txt and \msdos.sys into line2.txt

I use character replacement on line.txt to change the contents to %X%

I read in and expand the %X%, then append the contents from line2.txt to create an object string.  Then "dir" the object to check for existence, if exist, append it to an additional line_final.txt, if not exist, then do nothing with the object string and read in the next line from the original.txt file and parse accordingly as above.  

As I write this, I see that your solution should work for what I am trying to do.  I will wait to see if you have any additional suggestions for a solution now that you know the rest of the story.
0
 

Author Comment

by:mouse050297
ID: 7218640
Forgot that this was still open.  Points are yours.
0

Featured Post

Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

Question has a verified solution.

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

Suggested Solutions

This article shows how to make a Windows 7 gadget that extends its U/I with a flyout panel -- a window that pops out next to the gadget.  The example gadget shows several additional techniques:  How to automatically resize a gadget or flyout panel t…
With most software applications trying to cater to multiple user needs nowadays, the focus is to make them as configurable as possible. For e.g., when creating Silverlight applications which will connect to WCF services, the service end point usuall…
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used.

765 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