Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/batch-file/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Batch file 如何将第二行输出批量存储到变量中?_Batch File - Fatal编程技术网

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"