for /f "tokens=5" %a in ('netstat -aon ^| findstr 9000') do tasklist /FI "PID eq %a"
其中9000应替换为您的端口号。
输出将包含这样的内容:
Image Name PID Session Name Session# Mem Usage========================= ======== ================ =========== ============java.exe 5312 Services 0 130,768 K
说明:
它遍历以下命令输出的每一行:
netstat -aon | findstr 9000
from every line, the PID (%a - the name is not important here) is extracted (PID is the 5th element in that line) and passed to the following command
tasklist /FI "PID eq 5312"
If you want to skip the header and the return of the command prompt, you can use:
echo off & (for /f "tokens=5" %a in ('netstat -aon ^| findstr 9000') do tasklist /NH /FI "PID eq %a") & echo on
Replace the [port_number] with the actual port number that you want to check and hit Enter.
If the port is being used by any application, then that application’s detail will be shown. The number, which is shown at the last column of the list, is the PID (process ID) of that application. Make note of this.
Type
tasklist | findstr '[PID]'
Replace the [PID] with the number from the above step and hit Enter.
You’ll be shown the application name that is using your port number.