1.

Solve : ping not responding in batch?

Answer»

Sorry to flood the forums (something like 4th thread in a month >.<), but my script SEEMS to stall on a certain command and I'm not sure why. I TRIED retyping the command into cmd and it worked, but when I try to run the script it stops on the command and just sits there. Any idea's?

Code: [Select]REM @echo off
@echo on
set c=0
if exist *.1 del /f *.1
setlocal EnableDelayedExpansion

REM set nam=%0
REM FOR /F "tokens=8 delims=\" %%G IN ("%nam%") DO (
REM set nam=%%G
REM )
REM FOR /F "tokens=1 delims=." %%G IN ("!nam!") DO (
REM set nam=%%G
REM )
REM title %nam%
title pingnet

net view | FIND "\\" >>network.1
echo.



for /f "delims=\\" %%G IN (network.1) DO (
set /a c+=1
echo %%G >>net!c!.1
)

set m=%c%
set c=0

:loop.ping
set /a c+=1
set /p y=<net%c%.1
ping %y% -n 1 | find "Min" >>ping%c%.1 <--------------------- Stalls on this command (even when i take out the redirect)
if %c% EQU %m% goto break.rename
goto loop.ping
:break.ping

set c=0

:loop.view
set /a c+=1
type net%c%.1
set /p a=<ping%c%.1
FOR /F "tokens=4 delims==" %%G IN ("%a%") DO (
del /f ping%c%.1
echo %%G >>ping%c%.1
)
if %c% EQU %m% goto break.view
goto loop.view
:break.view

:__
set c=0
set b=0
:1
set /a c+=1
del /f ping%c%.1
set /p a=<net%c%.1
ping %a%| find "Min" >>ping%c%.1
set /p a=<ping%c%.1
FOR /F "tokens=4 delims==" %%G IN ("%a%") DO (
del /f ping%c%.1
echo %%G >>ping%c%.1
)
:2
set /a b+=1
if %b% EQU %c% goto 3
type net%b%.1
type ping%b%.1
goto 2

:3
set /p 0=< net%c%.1
echo %0%*
type ping%c%.1
if %c% EQU %m% goto __
:4
set /a b+=1
type net%b%.1
type ping%b%.1
if %c% EQU %m% goto __
goto 1

screen output:
Code: [Select]

C:\Users\andude3\Documents\bat>set c=0

C:\Users\andude3\Documents\bat>if exist *.1 del /f *.1

C:\Users\andude3\Documents\bat>setlocal EnableDelayedExpansion

C:\Users\andude3\Documents\bat>REM set nam="C:\Users\andude3\Documents\bat\pingn
etAutoUpdate.bat"

C:\Users\andude3\Documents\bat>REM FOR /F "tokens=8 delims=\" %G IN ("") DO (

C:\Users\andude3\Documents\bat>REM set nam=%G

C:\Users\andude3\Documents\bat>REM )

C:\Users\andude3\Documents\bat>REM FOR /F "tokens=1 delims=." %G IN ("!nam!") DO
(

C:\Users\andude3\Documents\bat>REM set nam=%G

C:\Users\andude3\Documents\bat>REM )

C:\Users\andude3\Documents\bat>REM title

C:\Users\andude3\Documents\bat>title pingnet

C:\Users\andude3\Documents\bat>net view | find "\\" 1>>network.1

C:\Users\andude3\Documents\bat>echo.


C:\Users\andude3\Documents\bat>for /F "delims=\\" %G IN (network.1) DO (
set /a c+=1
echo %G 1>>net!c!.1
)

C:\Users\andude3\Documents\bat>(
set /a c+=1
echo LEMONILLA
1>>net!c!.1
)

C:\Users\andude3\Documents\bat>(
set /a c+=1
echo NATHANSCHOOL
1>>net!c!.1
)

C:\Users\andude3\Documents\bat>set m=2

C:\Users\andude3\Documents\bat>set c=0

C:\Users\andude3\Documents\bat>set /a c+=1

C:\Users\andude3\Documents\bat>set /p y= 0<net1.1

C:\Users\andude3\Documents\bat>ping LEMONILLA
-n 1 | find "Min" 1>>ping1.1
I was going to suggest using @echo on but I see you have already tried that.

By the way the second line below is redundant...

REM @echo off
@echo on

Your output seems to be from a different script. The one you posted does not seem to have echo LEMONILLA or echo NATHANSCHOOL in it

For some reason the window uses wordwrap when I run the scrip, it says echo LEMONILLA on one line when in fact the line is cut into 2 diffrent segments on the screen. The command from the scrip is
Code: [Select]echo %y% >>net!c!.1
where:
y = LEMONILLA
c = 1

this is also true with ping, which sticks. could this have something to do with the problem?You code shows a label called break.rename but does it exist?

If so then try this to see if the ping line is executing in an endless fashion.

Code: [Select]:loop.ping
set /a c+=1
set /p y=<net%c%.1
ping %y% -n 1 | find "Min" >>ping%c%.1 <--------------------- Stalls on this command (even when i take out the redirect)

echo %c% %m%

if %c% EQU %m% goto break.rename
goto loop.pingQuote from: foxidrive on July 11, 2012, 08:19:27 AM

You code shows a label called break.rename but does it exist?

If so then try this to see if the ping line is executing in an endless fashion.

Code: [Select]:loop.ping
set /a c+=1
set /p y=<net%c%.1
ping %y% -n 1 | find "Min" >>ping%c%.1 <--------------------- Stalls on this command (even when i take out the redirect)

echo %c% %m%

if %c% EQU %m% goto break.rename
goto loop.ping

I made the change, and also added the echo %c% you did for testing, but it never echoed. Thank you for the response.Does %y% expand to a meaningful ip or host name?
Host name, in the case of the stall 'LEMONILLA' which is the host computer.You are trying to ping localhost using its network name?

To test this try changing this

ping %y% -n 1 | find "Min" >>ping%c%.1

to this

ping %y% -n 1
pause

and watch it to see what the error message is.That seems to be the problem :/ I'm not actually getting an error.
Code: [Select]C:\Users\andude3\Documents\bat>(
set /a c+=1
echo NATHANSCHOOL
1>>net!c!.1
)

C:\Users\andude3\Documents\bat>set m=2

C:\Users\andude3\Documents\bat>set c=0

C:\Users\andude3\Documents\bat>set /a c+=1

C:\Users\andude3\Documents\bat>set /p y= 0<net1.1

C:\Users\andude3\Documents\bat>ping LEMONILLA
-n 1

\\LEMONILLA
\\NATHANSCHOOL

\\

No idea why it's showing the network, or why it is waiting for a prompt. Usually pause gives a written prompt, but this only response to enter. when you press enter you get :

Code: [Select]FIND: Parameter format not correct
ad
FIND: Parameter format not correct
aasdfasdf
FIND: Parameter format not correct

This HAPPENED even when I deleted the pipe (not just REMed it out).

I guess this is a start, but I still have no idea what it is talking about. Thank you for your help.Have you got a find.bat and/or ping.bat (or .cmd) in the same folder?
Quote from: Salmon Trout on July 11, 2012, 07:53:37 PM
Have you got a find.bat and/or ping.bat (or .cmd) in the same folder?

Or anywhere on the path. Is this batch file you are using called ping?Quote from: foxidrive on July 11, 2012, 11:08:24 PM
Or anywhere on the path. Is this batch file you are using called ping?
Quote from: Salmon Trout on July 11, 2012, 07:53:37 PM
Have you got a find.bat and/or ping.bat (or .cmd) in the same folder?

That's not the first time someone has made that mistake on this forum.Quote from: Squashman on July 12, 2012, 05:46:38 AM
That's not the first time someone has made that mistake on this forum.

It's the first thing I think of in a situation like this, along with a new variable called PATH .
Quote from: foxidrive on July 11, 2012, 11:08:24 PM
Or anywhere on the path. Is this batch file you are using called ping?
LOL yup. Changed it'd name and that part works now. Thank a bunch.


Discussion

No Comment Found