China DOS Union

-- Unite DOS · Advance DOS · Grow DOS --

Union site: www.cn-dos.net Forum site: www.cn-dos.net/forum
DOS stands for freedom, openness and progress. Let us work hard, learn from the openness and GNU spirit of FreeDOS and Linux, and together build and grow a free GNU GPL world!

中国DOS联盟论坛
The time now is 2026-06-19 23:56
中国DOS联盟论坛 » DOS批处理 & 脚本技术(批处理室) » [Discussion] 2 times ping 1 is not equal to 1 time ping 2 View 2,175 Replies 2
Original Poster Posted 2008-12-27 17:30 ·  中国 广东 揭阳 电信
银牌会员
★★★★
SuperCleaner
Credits 2,362
Posts 1,133
Joined 2008-02-02 21:36
18-year member
UID 110072
Gender Male
Status Offline
Title: 2 pings of 1 are not equal to 1 ping of 2

Text / 523066680
::

Here ping1 refers to ping -n 1 127.1>nul; ping2 refers to ping -n 2 127.1>nul

Accidentally discovered that for /l %%a in (1,1,2) do (ping -n 1 127.1>nul) is quite different in waiting time from ping -n 2 127.1>nul, so they are not equal.
I tried changing the 2 in the for to 9 and it still didn't take more than a second. I felt this "precision" was still okay, so later I always used it when writing special effects. When I started learning batch processing, I was very random, and then simplified it to
for /l %%a in (1,1,2) do (ping -n>nul)
Finally, when I posted the code in the group, someone asked why not just ping -n 2 127.1>nul (hereinafter referred to as ping2)
I replied that the time of ping2 is greater than the time of two ping1s, and the effect of two ping1s is just right.
Later, HAT said that directly "ping -n>nul" is a wrong sentence. If the effect achieved by ping -n>nul is the case, then other commands should be the same. So taking attrib as an example, I tried it and the time was really the same, so I left the line dizzy.
Alas, I forgot to refute. If you use echo, you have to do it hundreds of times. Attrib also has a little delay just right.

The following sorts out personal views:
Later I saw some batch processing examples: batch processing that reads articles character by character and some special effects, etc.
In order to achieve a suitable speed, some use thousands of echos, and some use generating sleep.xxx

I think the method I advocate is better. Let's use code:

@echo off
color 4e
set str= cn-dos 523066680 祝 大 家 新 年 快 乐 !
for /l %%a in (0,1,50) do (
call,set /p x=%%str:~%%a,1%%<nul
for /l %%b in (1,1,5) do (ping -n 1 127.0>nul)
)
exit


How about? Is the typing speed just right?

For this typing effect, the disadvantage of thousands of echos,>nul is that the number of executions is large, and the delay time may be different for different computers.

ping -n 2 127.1>nul has too long a typing delay time.

I have nothing to say about generating sleep, it's just that I don't get used to it....

The advantage of for /l %%b in (1,1,N) do (ping -n 1 127.0>nul) is that the time for 1-9 times is all within 1 second. You can choose 1-9 times to achieve a more detailed delay effect. Compared with echo, the number of times is easier to choose, and the effect is generally the same for different computers.

(Range is generally selected from 1-9, and if it is larger, it is close to seconds...)
Recent Ratings for This Post ( 1 in total) Click for details
RaterScoreTime
HAT +4 2008-12-28 00:31
Floor 2 Posted 2008-12-27 18:01 ·  中国 上海 电信
中级用户
★★
Credits 484
Posts 250
Joined 2007-06-05 23:33
19-year member
UID 90372
Gender Male
Status Offline
I don't know if anyone has calculated the miscellaneous time consumption of ping...
ping -n 1 -w 2850 99>nul
Floor 3 Posted 2008-12-28 13:59 ·  中国 广东 江门 电信
中级用户
★★
Credits 338
Posts 175
Joined 2007-10-21 15:30
18-year member
UID 100351
Gender Male
Status Offline
Personally, I think it has something to do with the tree-planting principle
Forum Jump: