user3474706
user3474706

Reputation: 33

MS-DOS Pipe the content of a file into a variable

I am trying to send the content of a text file (which is just one word) into a variable in MS-DOS.

I tried doing it with pipes like so ,without any success

TYPE username.txt | %savedName%

Can anyone enlighten me?

Upvotes: 2

Views: 3204

Answers (2)

VinyJones
VinyJones

Reputation: 1014

this one is working fine and simpler

set /p SCHEMAS=<schemas_file.txt

Upvotes: 0

Magoo
Magoo

Reputation: 80033

for /f "delims=" %%i in (username.txt) do set "savedname=%%i"
echo savedname=%savedname%

should work for you (as a batch file). If you are executing directly from the prompt, then reduce each %% to %.

If you are nunning this on a Windows machine using WIN NT4, Win2000, WINXP, WIN7, Vista or Win8 then this should work (as also the set/p approach should have worked)

If you are using Win95, Win98, WinME or real MSDOS, then a different approach would be required.

"MSDOS" is often used to mean "Command Prompt" - a generic term ridiculously misapplied to mean "A windows application which emulates the functionality of the MSDOS command-interpreter (with enhanced functionality)". Unfortunately, since "AWAWETFOTMCI(WEF)" is such a mouthful, many people abbreviate it to "MSDOS" or "DOS". This raises the ire of that sad section of the computing community that is more interested in asserting that MSDOS no longer exists than in communicating effectively.

Upvotes: 4

Related Questions