我尝试打印命令输出的时间(以 ping 为例)。
echo([!time!] start
for /f "usebackq delims= eol=" %%A in (`ping ::1`) do (
echo([!time!] __ %%A
)
echo([!time!] finish
但结果我得到了
[12:37:08.78] start
[12:37:12.04] __ Pinging ::1 with 32 bytes of data:
[12:37:12.04] __ Reply from ::1: time<1ms
[12:37:12.04] __ Reply from ::1: time<1ms
[12:37:12.04] __ Reply from ::1: time<1ms
[12:37:12.04] __ Reply from ::1: time<1ms
[12:37:12.04] __ Ping statistics for ::1:
[12:37:12.04] __ Packets: Sent = 4, Received = 4, Lost = 0 (0% loss),
[12:37:12.04] __ Approximate round trip times in milli-seconds:
[12:37:12.04] __ Minimum = 0ms, Maximum = 0ms, Average = 0ms
[12:37:12.04] finish
看起来循环仅在命令完成后才开始工作。有没有办法在命令完成之前处理命令输出?