Batch file 如何将第二行输出批量存储到变量中?
我要运行此命令:Batch file 如何将第二行输出批量存储到变量中?,batch-file,Batch File,我要运行此命令: wmic useraccount where name='%username%' get sid 它输出3行: SID 12345 *blank space* 我需要将第二行的sidnumber存储为变量 for /f "skip=1delims=" %%a in ( 'wmic useraccount where name="%username%" get sid' ) do set "sid=%%a"&goto next :next 或 skip=1跳过来自
wmic useraccount where name='%username%' get sid
它输出3行:
SID
12345
*blank space*
我需要将第二行的sid
number存储为变量
for /f "skip=1delims=" %%a in (
'wmic useraccount where name="%username%" get sid'
) do set "sid=%%a"&goto next
:next
或
skip=1
跳过来自wmic
命令的输出的第一行(注意,使用此格式,内部引号需要“
)。在第一个示例中,for循环的被突然终止,而在第二个示例中,变量sid
被分配到跳过行之后的第一行,然后忽略下面的行。谢谢!这个空格真的把我搞砸了,但是您给出的第二个解决方案非常有效。
set "sid="
for /f "skip=1delims=" %%a in (
'wmic useraccount where name="%username%" get sid'
) do if not defined sid set "sid=%%a"