Windows下bat脚本文件编写

文章目录

先给个实例来表示 使用杀死 指定端口

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
@echo off
set default_port=8080
set /p port=type need killed port (press enter for default port %default_port%): %=%
if "%port%"=="" set "port=%default_port%"
rem set /p port=type need killed port:

for /f "tokens=5 delims= " %%a IN ('netstat -a -n -o ^| findstr :%port%.*LISTENING') do (
set pid=%%a
)
if not defined pid (
echo not found port %port%
) else (
taskkill /F /pid %pid%
echo already kill %port%
)


set /p port=type need killed port:
for /f "tokens=5 delims= " %%a IN ('netstat -a -n -o ^| findstr :%port%.*LISTENING') do (
set pid=%%a
)
if not defined pid (
echo not found port %port%
) else (
taskkill /F /pid %pid%
echo already kill %port%
)



set /p port=type need killed port:
for /f "tokens=5 delims= " %%a IN ('netstat -a -n -o ^| findstr :%port%.*LISTENING') do (
set pid=%%a
)
if not defined pid (
echo not found port %port%
) else (
taskkill /F /pid %pid%
echo already kill %port%
)


pause