Computing.Net > Forums > Programming > Batch with ping produces no output

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

Batch with ping produces no output

Reply to Message Icon

Name: spoonman184
Date: November 22, 2008 at 18:22:56 Pacific
OS: Win XP SP2
CPU/Ram: AMD X2 4400+ 2 GB DD
Product: ACER M3100
Comment:

I was trying to reformat a ping command in batch to only produce what I wanted. However after running the file, it wouldn't output a single thing other than the set /p command and the pause.

@echo off
cd C:\windows\system32
set /p host="Enter host to ping "
ping %host% |find "average"
ping %host% |find "average"
ping %host% |find "average"
pause

crappy OEM comptuers...



Sponsored Link
Ads by Google

Response Number 1
Name: Judago
Date: November 22, 2008 at 18:46:05 Pacific
Reply:

Add the /i switch to your find comand or make the a in average uppercase(Average).

Of course nothing will be displayed if the host doesn't reply because Average doesn't appear in a failed ping.


0

Response Number 2
Name: spoonman184
Date: November 22, 2008 at 18:55:15 Pacific
Reply:

Thanks.

Is there a way to FIND both the string "average" and "timed"?

crappy OEM comptuers...


0

Response Number 3
Name: Judago
Date: November 22, 2008 at 19:25:33 Pacific
Reply:

It's easier to use findstr with multiple search terms.


ping %host%|findstr /i "average timed"

On a default ping "timed out" appears 4 time because the default echo request is four. It would also be what ever x in ping -n x 127.0.0.1.

It may be easier to use the errorlevel find will set if it can't find "Average"


@echo off
set /p host="Enter host to ping "
ping %host% |find /i "average"
if errorlevel 1 echo The request timed out because the host didn't reply.
pause

A couple of side notes:

You shouldn't need to cd into the system32 folder unless something is wrong with your path or pathext enviroment variables. It's a good idea to not use these names for variables, in fact there is a whole list of special variable names that shouldn't be used, type "set" at the command line(make sure the cmd window it's freshly opened) for the list, what ever is to the left of "=" probably shouldn't be used to set a value to.

Ping is one of the few commands included with windows that is case sensitive, it likes it switches to be in lower case.


0

Response Number 4
Name: Mechanix2Go
Date: November 22, 2008 at 20:59:04 Pacific
Reply:

" Ping is one of the few commands included with windows that is case sensitive, it likes it switches to be in lower case."

More www [wacky world of windows]


=====================================
If at first you don't succeed, you're about average.

M2


0

Response Number 5
Name: spoonman184
Date: November 22, 2008 at 21:44:50 Pacific
Reply:

The reason I CD into system 32 is that I made a script to check my IPCONFIG also using FIND, but when I included FIND it wouldn't work unless I CDed first.

crappy OEM comptuers...


0

Related Posts

See More



Response Number 6
Name: Mechanix2Go
Date: November 22, 2008 at 21:50:41 Pacific
Reply:

Like he said, better fix your PATH.


=====================================
If at first you don't succeed, you're about average.

M2


0

Response Number 7
Name: spoonman184
Date: November 22, 2008 at 21:58:20 Pacific
Reply:

Didn't see anything out of place. Mind going over it for me please?

Also, whats the markup language used to post code? I have tried both html and BB for CODE and neither works =\...

ALLUSERSPROFILE=C:\Documents and Settings\All Users
APPDATA=C:\Documents and Settings\User\Application Data
CLIENTNAME=Console
CommonProgramFiles=C:\Program Files\Common Files
COMPUTERNAME=XXXXX
ComSpec=C:\WINDOWS\system32\cmd.exe
FP_NO_HOST_CHECK=NO
HOMEDRIVE=C:
HOMEPATH=\Documents and Settings\User
LOGONSERVER=\\XXXXX
NUMBER_OF_PROCESSORS=2
OPENSSL_CONF=C:\Program Files\OpenSSL\bin\openssl.cfg
OS=Windows_NT
Path=C:\WINDOWS\system32;C:\WINDOWS;C:\Program Files\Image Concerter;C:\Program Files\Image Concerter\Microsoft.VC80.CRT;C:\Program Files\Image Concerter\Microsoft.VC80.MFC;C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\System32\wbem
PATHEXT=.COM;.EXE;.BAT;.CMD;.VBS;.VBE;.JS;.JSE;.WSF;.WSH
PROCESSOR_ARCHITECTURE=x86
PROCESSOR_IDENTIFIER=x86 Family 15 Model 107 Stepping 1, AuthenticAMD
PROCESSOR_LEVEL=15
PROCESSOR_REVISION=6b01
ProgramFiles=C:\Program Files
PROMPT=$P$G
SESSIONNAME=Console
SystemDrive=C:
SystemRoot=C:\WINDOWS
TEMP=C:\DOCUME~1\User\LOCALS~1\Temp
TMP=C:\DOCUME~1\User\LOCALS~1\Temp
tvdumpflags=8
USERDOMAIN=XXXXX
USERNAME=User
USERPROFILE=C:\Documents and Settings\User
VS90COMNTOOLS=C:\Program Files\C++ Microsoft Visual Studio 9.0\Common7\Tools\
windir=C:\WINDOWS

crappy OEM comptuers...


0

Response Number 8
Name: Mechanix2Go
Date: November 22, 2008 at 23:02:04 Pacific
Reply:

"when I included FIND it wouldn't work"

Means what? Do you get something like:

find is not recognized as an internal or external command

Either FIND is in the path or it isn't. Not much grey area there.


=====================================
If at first you don't succeed, you're about average.

M2


0

Response Number 9
Name: spoonman184
Date: November 22, 2008 at 23:08:39 Pacific
Reply:

Here is the specific batch file:

@echo off
cd C:\windows\system32
ipconfig |find /v "Subnet"
pause

When I do not include CD the batch file hangs. It does not output anything. When I try to close it, it displays ^C (not sure which key it is referring too). It closes after several long lines of ^C.

crappy OEM comptuers...


0

Response Number 10
Name: Mechanix2Go
Date: November 22, 2008 at 23:39:28 Pacific
Reply:

What drive and directory is it in before you CD?


=====================================
If at first you don't succeed, you're about average.

M2


0

Response Number 11
Name: spoonman184
Date: November 22, 2008 at 23:42:51 Pacific
Reply:

C:\Documents and Settings\User\Desktop>

crappy OEM comptuers...


0

Response Number 12
Name: Mechanix2Go
Date: November 23, 2008 at 00:26:04 Pacific
Reply:

No idea; I ran it from here with no prob.

C:\Documents and Settings\Administrator\Desktop>


=====================================
If at first you don't succeed, you're about average.

M2


0

Response Number 13
Name: Judago
Date: November 23, 2008 at 00:46:15 Pacific
Reply:

@ECHO OFF
ipconfig |find /v "Subnet"
pause

Works fine for me but now you mention it I do remember reading something about ipconfig not liking certain adaptor/configurations. Occasionally these external commands have inconsistencies, the fun part is learning what they are....

Just out of interest what is the name of this batch?

The markup here seems to be a mix of plain text and html. Line breaks seem to be converted to <br> and there are a few traps, tabs are converted to spaces and sometimes things get truncated. I even found a new one with this post, &lt and &gt display properly but come back as the actual symbol when editing and inturn create aline break in the post..


0

Response Number 14
Name: spoonman184
Date: November 23, 2008 at 00:51:25 Pacific
Reply:

Thats whats going on most likely, the naming of the batch file. I name them after the command which I am formatting. I will try renaming and see what that does.

crappy OEM comptuers...


0

Response Number 15
Name: spoonman184
Date: November 23, 2008 at 00:53:37 Pacific
Reply:

LOL That is whats going on. Running a batch file in which you are finding a string from an output of a command that is also the name of the batch file, it will fail to execute.

crappy OEM comptuers...


0

Response Number 16
Name: Mechanix2Go
Date: November 23, 2008 at 01:00:40 Pacific
Reply:

"I name them after the command which I am formatting."

Now there's a bad idea.


=====================================
If at first you don't succeed, you're about average.

M2


0

Response Number 17
Name: BatchFreak
Date: November 23, 2008 at 19:51:07 Pacific
Reply:

Didn't see anything out of place. Mind going over it for me please?

Also, whats the markup language used to post code? I have tried both html and BB for CODE and neither works =\...

ALLUSERSPROFILE=C:\Documents and Settings\All Users
APPDATA=C:\Documents and Settings\User\Application Data
CLIENTNAME=Console
CommonProgramFiles=C:\Program Files\Common Files
COMPUTERNAME=XXXXX
ComSpec=C:\WINDOWS\system32\cmd.exe
FP_NO_HOST_CHECK=NO
HOMEDRIVE=C:
HOMEPATH=\Documents and Settings\User
LOGONSERVER=\\XXXXX
NUMBER_OF_PROCESSORS=2
OPENSSL_CONF=C:\Program Files\OpenSSL\bin\openssl.cfg
OS=Windows_NT
Path=C:\WINDOWS\system32;C:\WINDOWS;C:\Program Files\Image Concerter;C:\Program Files\Image Concerter\Microsoft.VC80.CRT;C:\Program Files\Image Concerter\Microsoft.VC80.MFC;C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\System32\wbem
PATHEXT=.COM;.EXE;.BAT;.CMD;.VBS;.VBE;.JS;.JSE;.WSF;.WSH
PROCESSOR_ARCHITECTURE=x86
PROCESSOR_IDENTIFIER=x86 Family 15 Model 107 Stepping 1, AuthenticAMD
PROCESSOR_LEVEL=15
PROCESSOR_REVISION=6b01
ProgramFiles=C:\Program Files
PROMPT=$P$G
SESSIONNAME=Console
SystemDrive=C:
SystemRoot=C:\WINDOWS
TEMP=C:\DOCUME~1\User\LOCALS~1\Temp
TMP=C:\DOCUME~1\User\LOCALS~1\Temp
tvdumpflags=8
USERDOMAIN=XXXXX
USERNAME=User
USERPROFILE=C:\Documents and Settings\User
VS90COMNTOOLS=C:\Program Files\C++ Microsoft Visual Studio 9.0\Common7\Tools\
windir=C:\WINDOWS

shouldn't
HOMEPATH=\windows\system32

I only Batch if possible, 2000 more lines of code, oh well.


0

Response Number 18
Name: Mechanix2Go
Date: November 23, 2008 at 23:18:24 Pacific
Reply:

#15 refers


=====================================
If at first you don't succeed, you're about average.

M2


0

Sponsored Link
Ads by Google
Reply to Message Icon






Post Locked

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.


Go to Programming Forum Home


Sponsored links

Ads by Google


Results for: Batch with ping produces no output

Batch file, ping results www.computing.net/answers/programming/batch-file-ping-results/14033.html

batch files , ping results www.computing.net/answers/programming/batch-files-ping-results/14790.html

transition from C to C++ www.computing.net/answers/programming/transition-from-c-to-c-/4079.html