Solved

Run a command in a batch file

Posted on 2006-11-15
4
718 Views
Last Modified: 2009-08-25
How can I run this command from a bat file and keep the window open (pause i guess) at the end?

for /L %a in (1,1,254) do @ping -n 1 -w 100 172.30.250.%a | find /i "reply"

TIA
0
Comment
Question by:ttist25
  • 2
4 Comments
 
LVL 22

Assisted Solution

by:Christopher McKay
Christopher McKay earned 250 total points
ID: 17951946
Why would you want to keep the window open?

The command as it is doesn't display the info to the screen.

Is the desired end result to have a list of the IP Addresses that have "Reply" in the response?

If so, try this as your batch file:
@echo off
for /L %%a in (1,1,254) do (
     ping -n 1 -w 100 172.30.250.%%a |find /i "reply"
     if errorlevel=0 echo 172.30.250.%%a >>c:\results.txt
     )



The above will save all of the IP addresses that "reply" to a text file called results.txt in you c:\

Hope this helps!

:o)

Bartender_1
0
 
LVL 30

Accepted Solution

by:
callrs earned 250 total points
ID: 17951947
Place this line into a batch file called, say "c:\temp\ping1.bat":

for /L %%a in (1,1,254) do @ping -n 1 -w 100 172.30.250.%%a | find /i "reply"

Then:
Start > Run > cmd /k c:\temp\ping1.bat

For more info, type this at the command prompt:
cmd /?

--
To simply pause, you could use the set command (type set /? for help):
set /p quit=Hit ENTER to continue
0
 
LVL 1

Author Comment

by:ttist25
ID: 17952860
Thanks guys!

I went ahead and created a batch file with the for statement and then dropped the cmd /k c:\pingall.bat in another bat file on the desktop.  
I was just hoping I could get it all together in one bat file.

In XP that command actually does display replies on the screen.  I tried it on a 2K server and it gave an error about not being able to find the file reply (or something like that).

I'm going to try your's on the 2k server bartender.

Thanks again!
0
 
LVL 30

Expert Comment

by:callrs
ID: 17953166
To get it into one file, and if all you need is a pause, instead of cmd /k you could use set /p which will hold the window open until you hit ENTER
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

The following is a collection of cases for strange behaviour when using advanced techniques in DOS batch files. You should have some basic experience in batch "programming", as I'm assuming some knowledge and not further explain the basics. For some…
TOMORROW TOMORROW.BAT is inspired by a question I get asked over and over again; that is, "How can I use batch file commands to obtain tomorrow's date?" The crux of this batch file revolves around the XCOPY command - a technique I discovered w…
This video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.

809 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question