Solved

Run a command in a batch file

Posted on 2006-11-15
4
689 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:Bartender_1
Bartender_1 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

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

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…
Being a system administrator some time we require to do things remotely, one of them is installing software. Here I am going to tell you how to install software through wmic (Windows management instrument console). I am not at all saying that this i…
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …

757 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

Need Help in Real-Time?

Connect with top rated Experts

23 Experts available now in Live!

Get 1:1 Help Now