问题
I need to get the very first line of the command line output not all line, For example if i give
C:\Temp> dir
I need display the Very first line only like,
11/15/2012 06:58 PM <DIR> .
How can i get this ?
Thanks in advance.
回答1:
One approach to get the first line of output for a given command is to execute the command in a FOR loop, then break out of the loop after the first line.
@ECHO OFF
SET COMMAND=dir
FOR /F "delims=" %%A IN ('%COMMAND%') DO (
SET TEMPVAR=%%A
GOTO :Print
)
:Print
ECHO %TEMPVAR%
来源:https://stackoverflow.com/questions/13601015/how-can-i-get-the-first-line-of-the-output-for-given-command-in-dos