0

How do I clear the command prompt screen before printing out netstat information when using a refresh interval?

I've been using netstat -anp TCP | Find "5000" to view information for a specific port. I've been attempting to add a refresh interval, but also clear the screen every time it's refreshed. The closest attempt I've made is:

netstat 1 -anp TCP | (cls & Find "5000")

With the above, I'm trying to run cls, followed by Find "5000" after every netstat refresh. However, it only runs cls once, and Find "5000" each time. Is something like this possible with netstat?

2
  • This can be accomplished by creating a small batch script. Would that work for you? Also, what operating system are you using?
    – and31415
    Aug 29, 2014 at 18:13
  • @and31415, I'm looking for a non batch solution for now. I'm using Windows 7, and it would be used on a couple version of Windows server. If something similar to what I provided isn't possible (and short), a batch script would work.
    – making3
    Aug 29, 2014 at 18:19

1 Answer 1

1

Since you're trying to depend on Netstat's internal Interval system it's what's causing you grief, as Netstat doesn't really "end" each time.

You could break it up a bit, remove the Netstat interval, and make it into a looping batch file.

This batch file should work on all versions of Windows (2000+ anyway)

@echo off
:GoAgain
cls
netstat -anp TCP | Find "5000"
ping localhost -n 2 >nul
goto GoAgain

The ping to localhost line is used to create an approx. 1 second pause before looping (on Vista+ you could use the timeout command instead to make it more accurate if you'd like).

To stop it, hit Ctrl+C to break out of the loop.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .