How can i get the first line of the output for given command in dos

时光毁灭记忆、已成空白 提交于 2019-12-30 09:39:15

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!