Solved

Run a command in a batch file

Posted on 2006-11-15
4
732 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 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

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

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

One of my most closely kept secrets is revealed in this discussion How to output text on the same line This question was recently posted in EE by Simon336697 (http://www.experts-exchange.com/Programming/Languages/Scripting/Shell/Batch/Q_2459…
VALIDATING DATES One method of validating dates is to jam the date into the DATE command and see if it accepts it by examining the system's errorlevel value. A non-zero result indicates failure. A typical example might look something like the fol…
This is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.
This tutorial will teach you the special effect of super speed similar to the fictional character Wally West aka "The Flash" After Shake : http://www.videocopilot.net/presets/after_shake/ All lightning effects with instructions : http://www.mediaf…

695 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