2014-07-15 89 views
0

我已經創建了一個批處理文件來測試主機本地網絡上的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

我不知道,如果這個問題更適合用於服務器故障。該問題已經存在:http://serverfault.com/questions/25112/how-to-launch-a-new-cmd-window-from-an-existing-cmd-window – Krumia

+0

謝謝。我試圖找到它,但我從來沒有見過這個帖子。 – LuckyLee

回答

0

在該行的TE開頭添加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" 
... 
+0

快速簡單。謝謝。現在我還有其他一些事情要解決,我已經做到了,但這使我走向了正確的方向。 – LuckyLee

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 /?就可以看到它們。

相關問題