Here's another technique for reading only the first line of a file using for /f and type that doesn't rely on set /p:
@echo off
setlocal enableextensions enabledelayedexpansion
set VAR=
set CURRLINE=0
for /f "delims=" %%a in ('type "test.txt"') do (
set /a CURRLINE+=1
if !CURRLINE! EQU 1 (
set VAR=%%a
goto :DONE
)
)
:DONE
echo %VAR%
endlocal
The advantage here is there's no need to write out a separate file.
However, note that either of these approaches (set /p or for /f with type) will have problems with special shell characters in the input file (<, >, |, etc.). To get around this problem, one could use a small utility I wrote a while back called shellesc.exe (http://www.westmesatech.com/sst.html) to "escape" the special characters. But if you use these tools, then you can also use linex.exe to pick the line you want and get the result with a little bit less code:
@echo off
setlocal enableextensions
set VAR=
for /f "delims=" %%a in ('type "test.txt" ^| linex -l 1 ^| shellesc') do set VAR=%%a
echo %VAR%
endlocal
Note that this approach has the additional advantage of not "choking" on special shell characters (shellesc).
HTH,
Bill