setting a variable with a ping result

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
bf_prg-bgnr
Posts: 5
Joined: 22 Jun 2013 21:27

setting a variable with a ping result

#1 Post by bf_prg-bgnr » 22 Jun 2013 21:31

hi guys!

i have this code:

ping -n 1 00.00.000.00 | find "Reply" >> icms_ping_log.txt

i want to put the result of "reply" into a variable instead of a text file.

how would i go about doing that or is there documentation that i can read that would help me with this?

thanks in advance for your assistance!!

Squashman
Expert
Posts: 4465
Joined: 23 Dec 2011 13:59

Re: setting a variable with a ping result

#2 Post by Squashman » 22 Jun 2013 22:14

Code: Select all

FOR /F "delims=" %%G in ('ping -n 1 00.00.000.00 ^| find "Reply"') DO SET pingreply=%%G

bf_prg-bgnr
Posts: 5
Joined: 22 Jun 2013 21:27

Re: setting a variable with a ping result

#3 Post by bf_prg-bgnr » 22 Jun 2013 23:04

thanks for the reply, squashman!

now, how could i insert the value in %%G into a textfile?

what i'm trying to do is create a data set into a text file. simple data set with two columns.

so, my result would be something like this in a text file

ip-address, result
00.00.000.00, whatever result
00.00.000.00, whatever result 2

of course the code has a loop in there.

foxidrive
Expert
Posts: 6031
Joined: 10 Feb 2012 02:20

Re: setting a variable with a ping result

#4 Post by foxidrive » 22 Jun 2013 23:08

Schoolwork?

bf_prg-bgnr
Posts: 5
Joined: 22 Jun 2013 21:27

Re: setting a variable with a ping result

#5 Post by bf_prg-bgnr » 23 Jun 2013 11:13

foxidrive, personal enhancement ;)

Squashman
Expert
Posts: 4465
Joined: 23 Dec 2011 13:59

Re: setting a variable with a ping result

#6 Post by Squashman » 23 Jun 2013 11:29

You need to explain better what you want out of this BATCH file.
Your original code was output to a text file and then you asked for it in a variable and now you want it back to a text file. Please clarify what you are doing! You are wasting everyone's time by rewriting the code every time you come back with another question.

bf_prg-bgnr
Posts: 5
Joined: 22 Jun 2013 21:27

Re: setting a variable with a ping result

#7 Post by bf_prg-bgnr » 23 Jun 2013 19:48

sorry squashman, don't mean to waste your time.

i really appreciated your first assistance.

i thought that my question was extremely simple:

put a value in a variable, then put that variable in a text file. Should be easy.

i wanted to figure the code out on my own based on what you have provided.

as i explained in the my last post, i'm trying to create a data set recording ping replies.

bf_prg-bgnr
Posts: 5
Joined: 22 Jun 2013 21:27

Re: setting a variable with a ping result

#8 Post by bf_prg-bgnr » 23 Jun 2013 19:51

by the way, if anyone can suggest a book or documentation related to my question. that would be extremely appreciated.

new to this batch file programming, but not new to programming.

Squashman
Expert
Posts: 4465
Joined: 23 Dec 2011 13:59

Re: setting a variable with a ping result

#9 Post by Squashman » 23 Jun 2013 20:35

bf_prg-bgnr wrote:by the way, if anyone can suggest a book or documentation related to my question. that would be extremely appreciated.

new to this batch file programming, but not new to programming.

What is wrong with our main website?

Squashman
Expert
Posts: 4465
Joined: 23 Dec 2011 13:59

Re: setting a variable with a ping result

#10 Post by Squashman » 24 Jun 2013 06:10

bf_prg-bgnr wrote:i thought that my question was extremely simple:

put a value in a variable, then put that variable in a text file. Should be easy.

The problem is you changed the parameters of your problem. You need to explain everything up front so that the code can be written once instead of rewriting the code. Has nothing to do with you thinking it is simple or easy. It is a lack of communication.

Code: Select all

FOR /F "tokens=3* delims=: " %%G in ('ping -n 1 00.00.000.00 ^| find "Reply"') DO >>icms_ping_log.txt echo %%G,%%H

Post Reply