中国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-30 22:52
47,813 topics / 349,918 posts / today 0 new / 48,279 members
DOS学习入门 & 精彩文章 (教学室) » Problems with PING
Printable Version  2,621 / 19
Floor1 marryli Posted 2007-03-08 11:14
初级用户 Posts 13 Credits 36
Make a batch script to test whether the connection to a certain IP address is normal. Below is what I wrote, very crude haha.

ping 17.0.11.1 > a.txt
type a.txt | find "ms" && echo ----Connection is normal----

Is there a way to determine connectivity without generating a .txt file?
Thanks
Floor2 marryli Posted 2007-03-08 12:08
初级用户 Posts 13 Credits 36
Too late, everyone is asleep?
Hehe
Floor3 xngem Posted 2007-03-09 03:42
新手上路 Posts 2 Credits 4
ping 17.0.11.1
pause
Floor4 lxmxn Posted 2007-03-09 05:22
版主 Posts 4,938 Credits 11,386
Floor5 blue812 Posted 2007-03-09 05:55
初级用户 Posts 29 Credits 57
Floor6 vkill Posted 2007-03-09 06:04
金牌会员 Posts 1,744 Credits 4,103 From 甘肃.临泽
Originally posted by lxmxn at 2007-3-9 05:22:

Why is it written so complicated?

ping -n 1 127.1>nul 2>nul &&(echo ok)
Floor7 Snickoow Posted 2007-03-09 08:30
初级用户 Posts 16 Credits 30 From 上海
Still not quite clear!
Floor8 marryli Posted 2007-03-10 08:36
初级用户 Posts 13 Credits 36
Often see this thing, also checked on the net. Also checked in the XP built-in help. Still didn't understand. Which boss can give an explanation? Thanks
Floor9 hxmupdata Posted 2007-03-11 10:35
初级用户 Posts 39 Credits 76
It seems that ping -n 1 127.1>nul&&echo ok is okay. What about 2>nul? Let me explain.

In the command line, 2>nul is used to redirect the standard error output (stderr) to the null device, which means to suppress the error messages. For example, if there is an error message that would normally be displayed, using 2>nul will make it not show up.
Floor10 electronixtar Posted 2007-03-11 11:02
铂金会员 Posts 2,672 Credits 7,493
Search by yourself, search in the forum
Floor11 hxmupdata Posted 2007-03-11 11:07
初级用户 Posts 39 Credits 76
Originally posted by marryli at 2007-3-7 22:14:
Make a batch script
Test if the connection to a certain IP address is normal
The following is what I wrote, very simple ha

ping 17.0.11.1 > a.txt
type a.txt | find "ms" && echo ----Connection normal----



There is ...

set count=10
:again
set b=false
ping 17.0.11.1|find "ms"&&set b=ok&&echo ----Connection normal------&&exit
if %b%==false echo -----Can't connect------
set count=count-1 ::Feels a bit wrong,....
if count==0 exit
goto again
Floor12 hxmupdata Posted 2007-03-11 11:43
初级用户 Posts 39 Credits 76
>It's redirection. The output of the command is displayed in cmd by default. Using > won't display it.
>nul releases the output
Floor13 lxmxn Posted 2007-03-12 00:43
版主 Posts 4,938 Credits 11,386
Originally posted by hxmupdata at 2007-3-10 22:07:
set count=10
:again
set b=false
ping 17.0.11.1|find "ms"&&set b=ok&&echo ----连接正常------&&exit
if %b%==false echo -----连接不到------
set count=count-1 ::感觉这有点不对,....
if count==0 exit
goto again

To perform arithmetic operations with set, you should add the "/a" parameter. It should be "set /a count=count-1"

[ Last edited by lxmxn on 2007-3-15 at 11:29 AM ]
Floor14 hxmupdata Posted 2007-03-12 06:20
初级用户 Posts 39 Credits 76
Originally posted by lxmxn at 2007-3-11 11:43:

You should add the parameter "/a" when using set for arithmetic operations, "set /a count==count-1"

Oh, I see. I'm just learning. I usually program in other languages...
Floor15 hxmupdata Posted 2007-03-12 06:26
初级用户 Posts 39 Credits 76
Ask a question: If you don't add "/a count=count-1", what will the value of count be? Why...
I don't know if my own understanding is correct
1 2  Next
[ Contact the Union admin team - 中国DOS联盟 - Standard version ]
Sponsored by ifanr Inc | © 2001–2023