Page 1 of 1

setting a variable with a ping result

Posted: 22 Jun 2013 21:31
by bf_prg-bgnr
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!!

Re: setting a variable with a ping result

Posted: 22 Jun 2013 22:14
by Squashman

Code: Select all

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

Re: setting a variable with a ping result

Posted: 22 Jun 2013 23:04
by bf_prg-bgnr
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.

Re: setting a variable with a ping result

Posted: 22 Jun 2013 23:08
by foxidrive
Schoolwork?

Re: setting a variable with a ping result

Posted: 23 Jun 2013 11:13
by bf_prg-bgnr
foxidrive, personal enhancement ;)

Re: setting a variable with a ping result

Posted: 23 Jun 2013 11:29
by Squashman
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.

Re: setting a variable with a ping result

Posted: 23 Jun 2013 19:48
by bf_prg-bgnr
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.

Re: setting a variable with a ping result

Posted: 23 Jun 2013 19:51
by bf_prg-bgnr
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.

Re: setting a variable with a ping result

Posted: 23 Jun 2013 20:35
by Squashman
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?

Re: setting a variable with a ping result

Posted: 24 Jun 2013 06:10
by Squashman
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