i want to store output of text file into a variable. So i can pass the whole file as parameter. I am using windows 2003 server
The text files having multiple lines like
10.20.210.100 fish
10.20.210.101 rockI was using
Set /P var=<file.txtit reads only 1st line of the file. So if file having only 1 line then it’s ok .
I tried with FOR LOOP also but it assigning the last value to variable.
Need help
You can't achieve that anyway since an environment variable is a string ended by a CR/LF. So it is not possible to store into one variable a multi-lines text file.
Do you want eaxh line in a separate var or all the lines strung together?
=====================================
Life is too important to be taken seriously.M2
all the lines strung together...
I got the Ans.. @echo off
SETLOCAL EnableDelayedExpansion
set "line="
for /f "delims=" %%a IN (example.txt) do (
set "line1=%%a"
set "line=!line1! and %%a"
)
echo !line!
or
echo %line%
can this be done for a command output as well ..
I tried the following code :-
@echo offSETLOCAL EnableDelayedExpansion
set "line="
for /f "delims=" %%a IN ('net use \\%computername%\C$ /delete /y') do (
set "line1=%%a"
set "line=!line1! and %%a"
)
echo error = !line!
But it didn't worked .. When I executed this batch file output was :-
The network connection could not be found.More help is available by typing NET HELPMSG 2250.
error =
last line was error = thats it!!.. I exepected it to be the above error message..
Could you help me here .. Thanks !
Yes (14) | ![]() | |
No (14) | ![]() | |
I don't know (15) | ![]() |