MHQ
asked on
Batch file with ping
@echo off
set /a errors=0
echo Trying to ping host %1
For /f "tokens=1" %%s in ('ping "-n" "1" %1') DO (
if "%%s"=="Svar" (
echo --Success--
goto END
)
)
echo !!Failed!!
:END
This code in my bat file returns whether a ping was sucessful or failed. ("Svar" is the swedish version of "Response" as in "Response received from xxx.xxx.xxx.xxx")
How do I add to the above code to make it show the time it too to receive the response when the ping is succesful?
Regards,
MHQ
set /a errors=0
echo Trying to ping host %1
For /f "tokens=1" %%s in ('ping "-n" "1" %1') DO (
if "%%s"=="Svar" (
echo --Success--
goto END
)
)
echo !!Failed!!
:END
This code in my bat file returns whether a ping was sucessful or failed. ("Svar" is the swedish version of "Response" as in "Response received from xxx.xxx.xxx.xxx")
How do I add to the above code to make it show the time it too to receive the response when the ping is succesful?
Regards,
MHQ
ASKER
I'm sorry, I missed a "k" in my post.. though you should have been ablse to see what I ment anyhow.. I want to display the time it tooK to receive the responce.. that is, the time in ms reported by the ping. Sorry for the confusion
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
That worked perfectly! But... how come it is stored in %%t ? What is that based on?
That's just the way it works. Open a command window and type "for /?" for a long list of information.
Basically, when you tell the for statement to get more than one token, it assigns them one by one in sequence beginning with the letter of the variable you specified in the statement, so for example:
for /f "tokens=1-5,*" %%a . . .
will assign tokens to %%a, %%b, %%c, %%d, %%e . . .
The "*" tells the statement to assign anything that might be left over to yet a 6th token, which will be %%f.
Therefore, if you have a lot to parse, best not to start with x, y, or z.
--
mrdtn
Basically, when you tell the for statement to get more than one token, it assigns them one by one in sequence beginning with the letter of the variable you specified in the statement, so for example:
for /f "tokens=1-5,*" %%a . . .
will assign tokens to %%a, %%b, %%c, %%d, %%e . . .
The "*" tells the statement to assign anything that might be left over to yet a 6th token, which will be %%f.
Therefore, if you have a lot to parse, best not to start with x, y, or z.
--
mrdtn
ASKER
Ic, didn't notice that "t" is after "s".. makes sence =) thanx alot!
It's subtle . . . but then if it weren't, it wouldn't be so much fun!!
Cheers,
mrdtn
Cheers,
mrdtn
@echo off
set /a errors=0
echo Trying to ping host %1
For /f "tokens=1" %%s in ('ping "-n" "1" %1') DO (
if "%%s"=="Svar" (
echo --Success-- at %date% %time%
goto END
)
)
echo !!Failed!!
:END