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-26 09:46
中国DOS联盟论坛 » DOS疑难解答 & 问题讨论 (解答室) » How can I use a return value from one parameter to verify whether my network is connected? View 1,062 Replies 11
Original Poster Posted 2003-07-02 00:00 ·  中国 河南 郑州 联通
初级用户
Credits 205
Posts 19
Joined 2003-06-06 00:00
23-year member
UID 3959
Gender Male
Status Offline
In a batch file I need to check whether my machine is connected to the Internet. What I'm using is to ping a website, save the result as text, then search it for a specified string. I don't know how to use errorlevel?
Floor 2 Posted 2003-07-02 00:00 ·  中国 广东 广州 增城区 电信
元老会员
★★★
Credits 1,468
Posts 407
Joined 2002-10-21 00:00
23-year member
UID 34
Gender Male
From 广州
Status Offline
Just use PING. If the PING succeeds, errorlevel is 0; if it fails, then it is 1. Written as a batch file:
@echo off
echo Please wait . . .
ping www.163.com >nul
if errorlevel 0 echo yes
if errorlevel 1 echo no


欢迎大家观临我的个人主页:

http://dosdiy.bluepc.com.cn/
http://dosdiy.ys168.com/


EMAIL: lydong@china.com.cn lydong@yeah.net
----------------------------------------------
Floor 3 Posted 2003-07-02 00:00 ·  中国 河南 郑州 联通
初级用户
Credits 205
Posts 19
Joined 2003-06-06 00:00
23-year member
UID 3959
Gender Male
Status Offline
So that's how it is, many thanks. I only knew the textbook said every command returns an erroelevel value, but I just didn't understand what it meant. In the future, if I have questions about batch files, I hope the moderator won't hesitate to give guidance.
Floor 4 Posted 2003-07-03 00:00 ·  中国 广东 广州 增城区 电信
元老会员
★★★
Credits 1,468
Posts 407
Joined 2002-10-21 00:00
23-year member
UID 34
Gender Male
From 广州
Status Offline
Sure, let's all learn together!
欢迎大家观临我的个人主页:

http://dosdiy.bluepc.com.cn/
http://dosdiy.ys168.com/


EMAIL: lydong@china.com.cn lydong@yeah.net
----------------------------------------------
Floor 5 Posted 2003-07-03 00:00 ·  美国 肯塔基州 费耶特县 列克星敦 Charter_Communications
系统支持
★★★★★★
“新DOS时代”站长
Credits 27,736
Posts 10,521
Joined 2002-10-09 12:00
23-year member
UID 9
Status Offline
if errorlevel 0 echo yes
if errorlevel 1 echo no

It should be changed to this, right:

if not errorlevel 1 echo yes
if errorlevel 1 echo no
Wengier - 新DOS时代

欢迎大家来到我的“新DOS时代”网站,里面有各类DOS软件和资料,地址:
http://wendos.mycool.net/

E-Mail & MSN: wengierwu AT hotmail.com (最近比较忙,有事请联系DOSroot和雨露,谢谢!)

Floor 6 Posted 2003-07-03 00:00 ·  中国 北京 科技网
银牌会员
★★★
颓废青年
Credits 2,265
Posts 721
Joined 2003-05-12 00:00
23-year member
UID 2032
Gender Male
Status Offline
What exactly is the difference?
if not errorlevel 0 echo no
if errorlevel 0 echo yes
Would that work?
Floor 7 Posted 2003-07-03 00:00 ·  中国 河南 南阳 联通
初级用户
Credits 205
Posts 19
Joined 2003-06-06 00:00
23-year member
UID 3959
Gender Male
Status Offline
Yes, after handling it that way, it seems in both cases it’s true. Can eq be used?

Also, what does the >nul after ping mean? Is it assigning to a value or creating a file?

Let me ask a few more questions at the same time, please help me sort them out:
1。How can I make a loop based on time, for example running once every minute? Can I jump out of the loop like break?
2。Can batch files recurse?
3。When do I need to use an escape character? Which symbol is it?


Floor 8 Posted 2003-07-11 00:00 ·  中国 广东 广州 电信
元老会员
★★★
Credits 1,468
Posts 407
Joined 2002-10-21 00:00
23-year member
UID 34
Gender Male
From 广州
Status Offline
The >nul after ping makes the text prompts produced after executing ping not display on the screen;
wanting to make a time-based loop may be a bit more complicated, but you can try CountDown, a tool used to run a program within a specified period of time (mainly used in batch files). Could you explain the second and third questions a bit more clearly?
欢迎大家观临我的个人主页:

http://dosdiy.bluepc.com.cn/
http://dosdiy.ys168.com/


EMAIL: lydong@china.com.cn lydong@yeah.net
----------------------------------------------
Floor 9 Posted 2003-07-11 00:00 ·  中国 湖北 武汉 硚口区 电信
元老会员
★★★★★
步行的人
Credits 9,654
Posts 3,351
Joined 2003-03-11 00:00
23-year member
UID 1113
Gender Male
From 湖北
Status Offline
Impressive...
弄花香满衣,掬水月在手。
明月鹭鸟飞, 芦花白马走。
我自一过后,野渡现横舟。
青云碧空在,净瓶水不流。
http://dos.e-stone.cn/guestbook/index.asp
======中國DOS聯盟=====
我的新网页http://rsds.7i24.com欢迎光顾
Floor 10 Posted 2003-07-11 00:00 ·  中国 河南 郑州 联通
初级用户
Credits 205
Posts 19
Joined 2003-06-06 00:00
23-year member
UID 3959
Gender Male
Status Offline
Isn't >nul something that's in the shell under linux? It works here too, huh
As for the second question, I mean whether a.bat can contain a call a.bat statement?
The third question is, if I want to use quotation marks inside quotation marks, or if I want to cancel the effect of a wildcard, how can I do it? For example
"he said: "..." " and wanting to find files ending with * .
Floor 11 Posted 2003-07-13 00:00 ·  中国 广东 广州 增城区 电信
元老会员
★★★
Credits 1,468
Posts 407
Joined 2002-10-21 00:00
23-year member
UID 34
Gender Male
From 广州
Status Offline
欢迎大家观临我的个人主页:

http://dosdiy.bluepc.com.cn/
http://dosdiy.ys168.com/


EMAIL: lydong@china.com.cn lydong@yeah.net
----------------------------------------------
Floor 12 Posted 2003-07-14 00:00 ·  中国 河南 郑州 联通
初级用户
Credits 205
Posts 19
Joined 2003-06-06 00:00
23-year member
UID 3959
Gender Male
Status Offline
Got it.
By the way, one off-topic question: are you an alumnus of Zhengzhou University? I originally came to this site from a recommendation in Computer News, and when I found that it was actually on a Zhengzhou University server, I was really quite pleased.
Forum Jump: