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

后端 未结 1 1453
猫巷女王i
猫巷女王i 2021-01-13 03:49

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 displ

1条回答
  •  伪装坚强ぢ
    2021-01-13 04:11

    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%
    

    0 讨论(0)
提交回复
热议问题