我创建了一个批处理文件来测试主机本地网络上的IP地址。它希望拉动其他机器的操作系统并将它们写入文本文件。
FOR /F "tokens=1 delims=:" %%d IN ('ping %computername% -4 -n 1 ^| find /i "reply"') DO FOR /F "tokens=3 delims= " %%g IN ("%%d") DO FOR /F "tokens=1 delims=." %%h IN ("%%g") DO FOR /F "tokens=2 delims=." %%i IN ("%%g") DO FOR /F "tokens=3 delims=." %%j IN ("%%g") DO WMIC /node:%%h.%%i.%%j.1 os get buildnumber,caption,CSDVersion /format:csv > C:\IP\IP.txt
FOR /F "tokens=1 delims=:" %%d IN ('ping %computername% -4 -n 1 ^| find /i "reply"') DO FOR /F "tokens=3 delims= " %%g IN ("%%d") DO FOR /F "tokens=1 delims=." %%h IN ("%%g") DO FOR /F "tokens=2 delims=." %%i IN ("%%g") DO FOR /F "tokens=3 delims=." %%j IN ("%%g") DO WMIC /node:%%h.%%i.%%j.2 os get buildnumber,caption,CSDVersion /format:csv >> C:\IP\IP.txt
FOR /F "tokens=1 delims=:" %%d IN ('ping %computername% -4 -n 1 ^| find /i "reply"') DO FOR /F "tokens=3 delims= " %%g IN ("%%d") DO FOR /F "tokens=1 delims=." %%h IN ("%%g") DO FOR /F "tokens=2 delims=." %%i IN ("%%g") DO FOR /F "tokens=3 delims=." %%j IN ("%%g") DO WMIC /node:%%h.%%i.%%j.3 os get buildnumber,caption,CSDVersion /format:csv >> C:\IP\IP.txt
(注意:我这里只显示3行,但实际文件遍历所有256个地址。)
它遍历每一行并写入文件就好了。但是,如果该IP没有任何内容,则需要30秒才能超时并转移到下一个IP。
我想为每一行打开一个新的cmd窗口并同时运行它们。一旦我完成了这个设置,我就将其修改为一次只运行10次 - 但我需要减少运行每一行所需的总时间。
我已尝试使用CMD / c运行它们(如下所示),但似乎还要等到每一行完成后再转到下一行。是否有一个CMD参数可以添加以使新窗口完全独立?
CMD /c "FOR /F "tokens=1 delims=:" %%d IN ('ping %computername% -4 -n 1 ^| find /i "reply"') DO FOR /F "tokens=3 delims= " %%g IN ("%%d") DO FOR /F "tokens=1 delims=." %%h IN ("%%g") DO FOR /F "tokens=2 delims=." %%i IN ("%%g") DO FOR /F "tokens=3 delims=." %%j IN ("%%g") DO WMIC /node:%%h.%%i.%%j.1 os get buildnumber,caption,CSDVersion /format:csv > C:\IP\IP.txt"
CMD /c "FOR /F "tokens=1 delims=:" %%d IN ('ping %computername% -4 -n 1 ^| find /i "reply"') DO FOR /F "tokens=3 delims= " %%g IN ("%%d") DO FOR /F "tokens=1 delims=." %%h IN ("%%g") DO FOR /F "tokens=2 delims=." %%i IN ("%%g") DO FOR /F "tokens=3 delims=." %%j IN ("%%g") DO WMIC /node:%%h.%%i.%%j.2 os get buildnumber,caption,CSDVersion /format:csv >> C:\IP\IP.txt"
CMD /c "FOR /F "tokens=1 delims=:" %%d IN ('ping %computername% -4 -n 1 ^| find /i "reply"') DO FOR /F "tokens=3 delims= " %%g IN ("%%d") DO FOR /F "tokens=1 delims=." %%h IN ("%%g") DO FOR /F "tokens=2 delims=." %%i IN ("%%g") DO FOR /F "tokens=3 delims=." %%j IN ("%%g") DO WMIC /node:%%h.%%i.%%j.3 os get buildnumber,caption,CSDVersion /format:csv >> C:\IP\IP.txt"
答案 0 :(得分:0)
您可以使用START
命令。你可能想要逃避双引号。
START "FOR /F ""tokens=1 delims=:"" %%d IN ('ping %computername% -4 -n 1 ^| find /i ""reply""') DO FOR /F ""tokens=3 delims= "" %%g IN (""%%d"") DO FOR /F ""tokens=1 delims=."" %%h IN (""%%g"") DO FOR /F ""tokens=2 delims=."" %%i IN (""%%g"") DO FOR /F ""tokens=3 delims=."" %%j IN (""%%g"") DO WMIC /node:%%h.%%i.%%j.1 os get buildnumber,caption,CSDVersion /format:csv > C:\IP\IP.txt"
要使其清洁,请将命令放在单独的批处理文件中并执行它。
START "Path\to\batch\file.bat"
START
命令提供了更多选项。您可能很清楚,只需给出命令START /?
即可看到它们。
答案 1 :(得分:0)
在行的开头添加START
:
START CMD /c "FOR /F "tokens=1 delims=:" %%d IN ('ping %computername% -4 -n 1 ^| find /i "reply"') DO FOR /F "tokens=3 delims= " %%g IN ("%%d") DO FOR /F "tokens=1 delims=." %%h IN ("%%g") DO FOR /F "tokens=2 delims=." %%i IN ("%%g") DO FOR /F "tokens=3 delims=." %%j IN ("%%g") DO WMIC /node:%%h.%%i.%%j.1 os get buildnumber,caption,CSDVersion /format:csv > C:\IP\IP.txt"
START CMD /c "FOR /F "tokens=1 delims=:" %%d IN ('ping %computername% -4 -n 1 ^| find /i "reply"') DO FOR /F "tokens=3 delims= " %%g IN ("%%d") DO FOR /F "tokens=1 delims=." %%h IN ("%%g") DO FOR /F "tokens=2 delims=." %%i IN ("%%g") DO FOR /F "tokens=3 delims=." %%j IN ("%%g") DO WMIC /node:%%h.%%i.%%j.2 os get buildnumber,caption,CSDVersion /format:csv >> C:\IP\IP.txt"
START CMD /c "FOR /F "tokens=1 delims=:" %%d IN ('ping %computername% -4 -n 1 ^| find /i "reply"') DO FOR /F "tokens=3 delims= " %%g IN ("%%d") DO FOR /F "tokens=1 delims=." %%h IN ("%%g") DO FOR /F "tokens=2 delims=." %%i IN ("%%g") DO FOR /F "tokens=3 delims=." %%j IN ("%%g") DO WMIC /node:%%h.%%i.%%j.3 os get buildnumber,caption,CSDVersion /format:csv >> C:\IP\IP.txt"
...