I'm looking for the DOS equivalent for this command:
foo=`cat bar`
Obviously, this sets the value of the variable foo to be equal to the contents of the file bar.
I want to do the same thing in a DOS shell.
Using Cygwin doesn't count. Perl isn't available. Bonus points for using only the tools that come with the Windows OS.
setx /f bar foo /a
(
Read more... )
Comments 10
Reply
I gave setx as an example that doesn't do what I want, but does allow setting an environment variable from a file. The problem is that it sets the global environment and that isn't available until I start a new command prompt. Using setx and starting a subshell of the existing shell doesn't work either, I tried that.
If I could set a variable based on the global environment I could use setx to read the file and set the global variable as an intermediate step.
Reply
Reply
http://gearbox.maem.umr.edu/batch/canned.responses.html
may help some,
http://gearbox.maem.umr.edu/batch/batchtoc.htm
and
http://www.batchfiles.co.nr/
Reply
I guess I wasn't missing a simple solution:
@echo off
:: filename.ext is the file to be processed
copy /y filename.ext %temp%.\t1.bat > nul
echo eEA BE 00 01 46 80 3C 0A 75 FA 81 EE> %temp%.\t2.dat
echo eF5 FA 00 89 F1 53 45 54 20 25 31 3D>> %temp%.\t2.dat
echo g=EA F9>> %temp%.\t2.dat
for %%? in (wF9 q) do echo %%?>> %temp%.\t2.dat
DEBUG %temp%.\t1.bat < %temp%.\t2.dat > nul
:: Set below the variable name where the string should be saved
call %temp%.\t1.bat MyString
for %%? in (t1.bat t2.dat) do del %temp%.\%%?
Yeah, that's the ticket. Construct a .COM file on the fly and run that. I suppose this is a good indicator that better alternatives are hard to come by.
What a silly operating system.
Reply
Reply
Reply
If I had echo -n it would be easy.
Can you give me an example?
Starting with an unknown value contained in a single line of a known file, I want to get the value into an environment variable in the current shell (command prompt).
Reply
Reply
assuming of course that your dos shell version supports the /p switch for set. (win 2k and above ships with it, I don't know about earlier). The 'discarded' part doesn't matter, it's just an input prompt for a user, into which contents of 'bar' is being fed.
Reply
Leave a comment