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

x
?
Solved

Windows batch scripting and variable expansion

Posted on 2002-03-29
3
Medium Priority
?
489 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
[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
  • 2
3 Comments
 
LVL 22

Accepted Solution

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

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

Question has a verified solution.

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

This article describes a technique for converting RTF (Rich Text Format) data to HTML and provides C++ source that does it all in just a few lines of code. Although RTF is coming to be considered a "legacy" format, it is still in common use... po…
After several hours of googling I could not gather any information on this topic. There are several ways of controlling the USB port connected to any storage device. The best example of that is by changing the registry value of "HKEY_LOCAL_MACHINE\S…
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…
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…

722 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