Tom's Guide | Tom's Hardware | Tom's Games
![]() |
![]() |
![]() |
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"
pausecrappy OEM comptuers...

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.

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.

" 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

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...

Like he said, better fix your PATH.
=====================================
If at first you don't succeed, you're about average.M2

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:\WINDOWScrappy OEM comptuers...

"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

Here is the specific batch file:
@echo off
cd C:\windows\system32
ipconfig |find /v "Subnet"
pauseWhen 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...

What drive and directory is it in before you CD?
=====================================
If at first you don't succeed, you're about average.M2

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

@ECHO OFF
ipconfig |find /v "Subnet"
pauseWorks 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, < and > display properly but come back as the actual symbol when editing and inturn create aline break in the post..

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...

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...

"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

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:\WINDOWSshouldn't
HOMEPATH=\windows\system32I only Batch if possible, 2000 more lines of code, oh well.

#15 refers
=====================================
If at first you don't succeed, you're about average.M2

![]() |
![]() |
![]() |

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