Solved

Windows batch scripting and variable expansion

Posted on 2002-03-29
3
476 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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
SQL to ElasticSearch Query 1 524
Issue testing the Class Library 4 43
Windows Process running 3 40
Build VS2015 project in bat command 3 70
For a while now I'v been searching for a circular progress control, much like the one you get when first starting your Silverlight application. I found a couple that were written in WPF and there were a few written in Silverlight, but all appeared o…
A theme is a collection of property settings that allow you to define the look of pages and controls, and then apply the look consistently across pages in an application. Themes can be made up of a set of elements: skins, style sheets, images, and o…
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…
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.

705 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

16 Experts available now in Live!

Get 1:1 Help Now