[英]How to use ping command as a variable to be used as breaking condition in a batch file?
I want to create a batch file to first ping a share drive on start to see if it is ready to be mapped, then map when the ping is returned. 我想创建一个批处理文件,首先在启动时ping一个共享驱动器,看它是否准备好映射,然后在返回ping时映射。 As psuedo, something like this:
像psuedo,这样的事情:
while true:
ping ipaddr -t
if (ping returned):
break
map drive
I believe the syntax would be something like: 我相信语法会是这样的:
:checkping
ping ipaddr -t
if ping:
goto mountZ
fi
goto checkping
:mountZ
net use Z:....
So how do I go about setting the ping in a usable variable to break the loop? 那么如何在可用变量中设置ping来打破循环呢?
@echo off
:checkping
ping 8.8.8.8 > nul
IF ERRORLEVEL 1 echo Not Connected & goto checkping
IF ERRORLEVEL 0 echo Connected & net use Z:....
pause
:loop
net use K: \\127.0.0.1\C$
If errorlevel 1 goto loop
Is one simple way of doing it. 这是一种简单的方法。
You could use the below. 你可以使用下面的内容。 If there is a TTL (Time To Live) then it will go to A, otherwise it will continue.
如果有TTL(生存时间),那么它将转到A,否则它将继续。
:checkping
ping -n 1 www.google.com | findstr TTL && goto a
goto checkping
Break
:a
REM Mapped Drive is connected
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.