在Windows批处理文件中的头-1
问题描述:
我想从windows PE中的以下命令输出只获得第一行。见下:在Windows批处理文件中的头-1
wmic nic where "NetConnectionStatus=2" get netconnectionid |findstr /v "^Net"|findstr /v "^$"
选择 - 第一将是一个选项,但它不起作用。 我对windows不太熟悉我对linux很熟悉。
我怎样才能得到输出的第一行。
如果可能没有findstr更好。
答
如何获得第一行描述为here at SO。但是你必须逃过^
和|
这样的字符,如this guide所述。
下剪断将工作:
@echo off
set "command=wmic nic where "netconnectionstatus=2" get netconnectionid ^| findstr /v "^^net" ^| findstr /v "^^$""
echo command: ^<%command%^>
for /f "delims=" %%a in ('%command%') do (
set tempvar=%%a
goto :print
)
:print
echo result: %tempvar%
我想最后管findstr /v "^^$""
是不必要的。
答
最后一个临时文件可以帮助最好的:
@echo off
wmic nic where "NetConnectionStatus=2" get netconnectionid |findstr /v "^Net"|findstr /v "^$" >tmp.tmp
set /p etc=<tmp.tmp
echo %etc%
的可能重复[我怎样才能输出用于在DOS命令给出的第一行(https://stackoverflow.com/questions/ 13601015 /我怎么能得到第一个输出的给定命令在DOS中) –
它应该工作,如果你能告诉我如何插入到命令下面的命令:wmic nic其中“NetConnectionStatus = 2”获得netconnectionid | findstr/v“^ Net”| findstr/v“^ $”,它抱怨|即使我逃避它。 – Badb0y