中国DOS联盟论坛

China DOS Union

-- Unite DOS · Advance DOS · Grow DOS --
Union site: www.cn-dos.net Forum site: www.cn-dos.net/forum
Guest | Log in | Register | Members | Search | China DOS Union
中国DOS联盟论坛
The time now is 2026-09-15 12:31
47,812 topics / 349,917 posts / today 0 new / 48,268 members
DOS批处理 & 脚本技术(批处理室) » What does "ping -n 1 127.1 > nul" mean?
Printable Version  19,293 / 73
Floor1 sglxy Posted 2006-10-25 02:15
中级用户 Posts 87 Credits 397
As the question says: I saw the statement "ping -n 1 127.1>nul" in several batch files. What does "ping -n 1 127.1>nul" mean? Can the experts explain it?
Floor2 vkill Posted 2006-10-25 02:17
金牌会员 Posts 1,744 Credits 4,103 From 甘肃.临泽
Start/Run hh ntcmds.chm::/ntcmds.htm
Floor3 9527 Posted 2006-10-25 02:20
银牌会员 Posts 438 Credits 1,185 From 北京
It mainly plays a role in delay, and there seems to be nothing else. 127.1 is the loopback address of this machine, which is equivalent to 127.0.0.1. Not only can 127.0.0.1 be written in the form of 127.1, but other types of IP addresses can also be, for example: 61.0.0.28 can also be written in the form of 61.28.
Floor4 sglxy Posted 2006-10-25 02:28
中级用户 Posts 87 Credits 397
Oh, I see. Thank you, two friends!
Floor5 lxmxn Posted 2006-10-25 08:23
版主 Posts 4,938 Credits 11,386
### About `ping -n 1 127.1>nul:`

1. `ping` is a network command to test network connectivity. The parameter "-n 1" means sending only one ICMPS packet to test network connectivity.

2. `127.1` represents the local reserved IP address, which is actually 127.0.0.1. Pinging 127.1 means pinging 127.0.0.1, which can test whether the network card and TCP/IP protocol are installed and working properly.

3. `>nul` means redirecting the screen display information generated by the command (>) to the null device (nul), so that the execution result of the ping command is not displayed on the screen. If you want to block error messages, you can use `>nul 2>nul` to block all screen output.
Floor6 xyxFlysky Posted 2006-10-25 10:38
新手上路 Posts 5 Credits 11
If you want to block error messages, you can use ">nul 2>nul" to block all screen output.

This sentence is not very understandable -_-
Floor7 lxmxn Posted 2006-10-25 11:04
版主 Posts 4,938 Credits 11,386

Re: xyxFlysky
  The ">nul 2>nul" can block all screen output. Here's the understanding:

  Suppose you execute a command but don't want to see the execution result on the screen. You can use " >nul" to block the output of the command on the screen. But some commands may produce error messages, and even using ">nul" can't block the information they generate. So adding " 2>nul" after it, that is, " >nul 2>nul", in this way, whether the command runs correctly or not, you won't see the screen display generated by this command.

  Let's take a simple example.

  The "dir" command can display the file and folder list of the current directory. At this time, if you use "dir >nul", you won't see the screen output of the dir command. Then what will happen if you type "dirr"? At this time, it will display " 'dirr' is not an internal command, nor an external command, nor a batch file." Then you may use "dirr >nul" to block this error message, but I tell you, your guess is wrong because the error message " 'dirr' is not an internal command, nor an external command, nor a batch file." will still appear. At this time, if you use "dirr >nul 2>nul", you won't see the above error message on the screen. I don't know if you understand it now.

  If you want to know more about the explanation of nul, you can search in the forum. You can find the detailed and wonderful explanation of the usage of nul by brother willsort.


[ Last edited by lxmxn on 2006-10-26 at 12:33 AM ]
Floor8 sglxy Posted 2006-10-25 18:55
中级用户 Posts 87 Credits 397
Brother lxmxn, your explanation is very detailed and has helped me understand the puzzles that I couldn't figure out before. I really appreciate your patient guidance, thank you!
Floor9 redtek Posted 2006-10-25 20:45
金牌会员 Posts 1,147 Credits 2,902
The example is really vivid, appreciate it~ :)
Floor10 amao Posted 2006-10-26 00:05
中级用户 Posts 152 Credits 316
Brother lxmxn has a very cool avatar, and he himself is very patient. Thumbs up!
Floor11 inhell Posted 2006-10-26 03:00
新手上路 Posts 4 Credits 10
If you understand Linux, it's easy to understand the concept of the null device
Floor12 yangzhiyi Posted 2006-10-29 00:49
中级用户 Posts 123 Credits 261
Ping -n 1 127.1>nul How to use this? I just want a similar usage. That is, executing ping -n 1 127.1>nul it will have no information. Then why execute it?

[ Last edited by yangzhiyi on 2006-10-29 at 12:51 AM ]
Floor13 zerocq Posted 2006-10-29 00:53
中级用户 Posts 196 Credits 458
Originally posted by yangzhiyi at 2006-10-29 00:49:
How to use the command "ping -n 1 127.1>nul"? I'm exactly looking for a similar usage.
That is, when you execute "ping -n 1 127.1>nul", there will be no any information. Then what is the purpose of executing it?
Please paste the original text for me to see.



Using the ping command to make the script run with a delay, that is, waiting for a few seconds before running the following.

I don't know the precision. :D

I use wscript.sleep:D
Floor14 yangzhiyi Posted 2006-10-29 01:02
中级用户 Posts 123 Credits 261
Crazy, the step-by-step execution of batch commands still needs to use delays. Usually, it's done with jumps. Using ping -n 1 127.1>nul for delays is even crazier.
Floor15 zhwvip Posted 2006-10-29 01:11
初级用户 Posts 14 Credits 29
1 2 3 45  Next
[ Contact the Union admin team - 中国DOS联盟 - Standard version ]
Sponsored by ifanr Inc | © 2001–2023