![]() |
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-08-15 23:59 |
47,813 topics / 349,903 posts / today 1 new / 48,258 members |
| DOS疑难解答 & 问题讨论 (解答室) » How can I use a return value from one parameter to verify whether my network is connected? |
| Printable Version 1,097 / 11 |
| Floor1 萍客 | Posted 2003-07-02 00:00 |
| 初级用户 Posts 19 Credits 205 | |
|
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?
|
|
| Floor2 Lydong | Posted 2003-07-02 00:00 |
| 元老会员 Posts 407 Credits 1,468 From 广州 | |
|
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 |
|
| Floor3 萍客 | Posted 2003-07-02 00:00 |
| 初级用户 Posts 19 Credits 205 | |
|
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.
|
|
| Floor4 Lydong | Posted 2003-07-03 00:00 |
| 元老会员 Posts 407 Credits 1,468 From 广州 | |
|
Sure, let's all learn together!
|
|
| Floor5 Wengier | Posted 2003-07-03 00:00 |
| 系统支持 Posts 10,521 Credits 27,736 | |
|
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 |
|
| Floor6 hunome | Posted 2003-07-03 00:00 |
| 银牌会员 Posts 721 Credits 2,265 | |
|
What exactly is the difference?
if not errorlevel 0 echo no if errorlevel 0 echo yes Would that work? |
|
| Floor7 萍客 | Posted 2003-07-03 00:00 |
| 初级用户 Posts 19 Credits 205 | |
|
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? |
|
| Floor8 Lydong | Posted 2003-07-11 00:00 |
| 元老会员 Posts 407 Credits 1,468 From 广州 | |
|
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? |
|
| Floor9 如是大师 | Posted 2003-07-11 00:00 |
| 元老会员 Posts 3,351 Credits 9,654 From 湖北 | |
|
Impressive...
|
|
| Floor10 萍客 | Posted 2003-07-11 00:00 |
| 初级用户 Posts 19 Credits 205 | |
|
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 * . |
|
| Floor11 Lydong | Posted 2003-07-13 00:00 |
| 元老会员 Posts 407 Credits 1,468 From 广州 | |
| Floor12 萍客 | Posted 2003-07-14 00:00 |
| 初级用户 Posts 19 Credits 205 | |
|
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. |
|
|
[ Contact the Union admin team -
中国DOS联盟 -
Standard version ] Sponsored by ifanr Inc | © 2001–2023 |