?
Solved

Run a command in a batch file

Posted on 2006-11-15
4
Medium Priority
?
734 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
4 Comments
 
LVL 22

Assisted Solution

by:Christopher McKay
Christopher McKay earned 1000 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 1000 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

Prepare for your VMware VCP6-DCV exam.

Josh Coen and Jason Langer have prepared the latest edition of VCP study guide. Both authors have been working in the IT field for more than a decade, and both hold VMware certifications. This 163-page guide covers all 10 of the exam blueprint sections.

Question has a verified solution.

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

Using dates in 'DOS' batch files has always been tricky as it has no built in ways of extracting date information.  There are many tricks using string manipulation to pull out parts of the %date% variable or output of the date /t command but these r…
YESTERDAY YESTERDAY.BAT is inspired by a previous article I wrote entitled: TOMORROW.BAT (http://www.experts-exchange.com/OS/Microsoft_Operating_Systems/MS_DOS/A_4196-Advanced-Batch-File-Programming-TOMORROW-BAT.html). The crux of this batch f…
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…
Have you created a query with information for a calendar? ... and then, abra-cadabra, the calendar is done?! I am going to show you how to make that happen. Visualize your data!  ... really see it To use the code to create a calendar from a q…

770 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