read first line ine a file

  • Thread starter Thread starter JIM.H.
  • Start date Start date
J

JIM.H.

Hello,
I need to read first line in a file, and I am using the
following three lines.

FOR /F "eol=; tokens=1" %%i in (%myFile%) do (set myPar=%%
i &GOTO:forend)
:forend
Echo %myPar%
There are other lines after this, that performs some other
operations.

Is this correct and secure way? I do not want FOR goes to
second line and print %myPar% again, that will cause
trouble.
Thanks,
Jim.
 
JIM.H. said:
Hello,
I need to read first line in a file, and I am using the
following three lines.

FOR /F "eol=; tokens=1" %%i in (%myFile%) do (set myPar=%%
i &GOTO:forend)
:forend
Echo %myPar%
There are other lines after this, that performs some other
operations.

Is this correct and secure way? I do not want FOR goes to
second line and print %myPar% again, that will cause
trouble.
Thanks,
Jim.

set /p first_line=<%myFile%
 
David Trimboli said:
What must terminate the line for the set command? EOL? CR? Both? Either?

Nothing. When the end of the pipe is detected, everything (within
reason) read upto that point is a assigned to the variable, unless
a carriage return (0x0D) is encountered, then just everthing before
the CR is assigned.
 
Back
Top