Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Windows batch scripting and variable expansion

Posted on 2002-03-29
3
Medium Priority
?
491 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 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

NEW Veeam Agent for Microsoft Windows

Backup and recover physical and cloud-based servers and workstations, as well as endpoint devices that belong to remote users. Avoid downtime and data loss quickly and easily for Windows-based physical or public cloud-based workloads!

Question has a verified solution.

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

This article surveys and compares options for encoding and decoding base64 data.  It includes source code in C++ as well as examples of how to use standard Windows API functions for these tasks. We'll look at the algorithms — how encoding and decodi…
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…
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…
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…

972 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