Solved

Batch file with ping

Posted on 2004-04-16
7
1,359 Views
Last Modified: 2012-06-27
@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
0
Comment
Question by:MHQ
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 3
7 Comments
 
LVL 6

Expert Comment

by:mrdtn
ID: 10843348
Simple.  Use %date% and %time% as shown below.

@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
0
 
LVL 3

Author Comment

by:MHQ
ID: 10844508
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
0
 
LVL 6

Accepted Solution

by:
mrdtn earned 100 total points
ID: 10844580
Extract token 5 as well.  It will show up as replacebale param %%t.  Let me know if this is what you were looking for.

--

mrdtn

--

@echo off
set /a errors=0
echo Trying to ping host %1
For /f "tokens=1,5" %%s in ('ping "-n" "1" %1') DO (
  if "%%s"=="Svar" (
    echo --Success-- %%t
    goto END
  )
)

echo !!Failed!!
:END
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 3

Author Comment

by:MHQ
ID: 10844874
That worked perfectly! But... how come it is stored in %%t ? What is that based on?
0
 
LVL 6

Expert Comment

by:mrdtn
ID: 10845788
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
0
 
LVL 3

Author Comment

by:MHQ
ID: 10845843
Ic, didn't notice that "t" is after "s".. makes sence =) thanx alot!
0
 
LVL 6

Expert Comment

by:mrdtn
ID: 10846019
It's subtle . . . but then if it weren't, it wouldn't be so much fun!!

Cheers,

mrdtn
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Output in PHP throwing alignment of data off issue 12 74
Vbscript & Batch: restart servers with delay condition 2 47
asp Google Map 2 92
Oracle programming for starter 14 75
Whether you've completed a degree in computer sciences or you're a self-taught programmer, writing your first lines of code in the real world is always a challenge. Here are some of the most common pitfalls for new programmers.
Today, the web development industry is booming, and many people consider it to be their vocation. The question you may be asking yourself is – how do I become a web developer?
In this fourth video of the Xpdf series, we discuss and demonstrate the PDFinfo utility, which retrieves the contents of a PDF's Info Dictionary, as well as some other information, including the page count. We show how to isolate the page count in a…

734 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question