我有這個腳本在Windows cmd文件,它做我想做的。它還顯示並記錄其輸出,但顯然該腳本中使用的程序的輸出不會按順序顯示和記錄。 請參閱下面的腳本和輸出。cmd /批處理文件沒有顯示,也沒有按順序記錄其他程序的輸出
@ECHO OFF
:: script global variables
SET log=nslookup-tests.log
::Logic
set LF=^
REM The two empty lines abive are required!!
set output=****%date% %time% -- NSLOOKUP from anywhere with DNS server from edpnet****
setlocal EnableDelayedExpansion
set output=!output!!LF!!LF!!LF!**youtube.com
set output=!output!!LF!!LF!*edpnet DNS
for /F "delims=" %%f in ('nslookup youtube.com 212.71.0.33') do (
set output=!output!!LF!%%f
)
set output=!output!!LF!!LF!*google DNS
for /F "delims=" %%f in ('nslookup youtube.com 8.8.8.8') do (
set output=!output!!LF!%%f
)
set output=!output!!LF!!LF!!LF!**bestofyoutube.com
set output=!output!!LF!!LF!*edpnet DNS
for /F "delims=" %%f in ('nslookup bestofyoutube.com 212.71.0.33') do (
set output=!output!!LF!%%f
)
set output=!output!!LF!!LF!*google DNS
for /F "delims=" %%f in ('nslookup bestofyoutube.com 8.8.8.8') do (
set output=!output!!LF!%%f
)
set output=!output!!LF!!LF!!LF!**vidzi.tv
set output=!output!!LF!!LF!*edpnet DNS
for /F "delims=" %%f in ('nslookup vidzi.tv 212.71.0.33') do (
set output=!output!!LF!%%f
)
set output=!output!!LF!!LF!*google DNS
for /F "delims=" %%f in ('nslookup vidzi.tv 8.8.8.8') do (
set output=!output!!LF!%%f
)
::output to screen and append to log file
echo !output!
echo !output!!LF!!LF!!LF!!LF! >> "!log!"
::Keep window open
cmd /k
輸出:
****wo 23/12/2015 9:46:18,94 -- NSLOOKUP from anywhere with DNS server from edpnet****
Non-authoritative answer:
Non-authoritative answer:
Non-authoritative answer:
Non-authoritative answer:
Non-authoritative answer:
Non-authoritative answer:
****do 24/12/2015 14:49:32,90 -- NSLOOKUP from anywhere with DNS server from edpnet****
**youtube.com
*edpnet DNS
Server: dns01.edpnet.net
Address: 212.71.0.33
Name: youtube.com
Addresses: 2a00:1450:4013:c00::5d
173.194.65.190
173.194.65.136
173.194.65.93
173.194.65.91
*google DNS
Server: google-public-dns-a.google.com
Address: 8.8.8.8
Name: youtube.com
Addresses: 2a00:1450:400c:c07::5b
85.234.204.215
85.234.204.236
85.234.204.251
85.234.204.226
85.234.204.237
85.234.204.211
85.234.204.245
85.234.204.230
85.234.204.241
85.234.204.222
85.234.204.221
85.234.204.207
85.234.204.249
85.234.204.219
85.234.204.234
**bestofyoutube.com
*edpnet DNS
Server: dns01.edpnet.net
Address: 212.71.0.33
Name: bestofyoutube.com
Address: 104.238.110.149
*google DNS
Server: google-public-dns-a.google.com
Address: 8.8.8.8
Name: bestofyoutube.com
Address: 104.238.110.149
**vidzi.tv
*edpnet DNS
Server: dns01.edpnet.net
Address: 212.71.0.33
Name: vidzi.tv
Addresses: 46.17.100.122
46.28.202.183
82.115.15.12
*google DNS
Server: google-public-dns-a.google.com
Address: 8.8.8.8
Name: vidzi.tv
Addresses: 82.115.15.12
46.28.202.183
46.17.100.122
輸出的次序是有點有序的,但也有出現在頂部,而不是在日誌文件中的Non-authoritative answer:
一堆。它們不會被追加到輸出變量中。
程序是否在訂單後執行,而不等待它完成?這看起來像異步行爲。