Thi*_*nka 2 port windows-xp batch-file
我正在编写一个批处理文件来自动检查端口80的可用性,并在其他程序使用时给出错误消息.但我不确定如何检查批处理文件中的端口80可用性.
我发现以下命令检查终端.
netstat -o -n -a | findstr 0.0:80
Run Code Online (Sandbox Code Playgroud)
但是我需要使用如下的批处理文件来检查它
if (!//port 80 is available) {
// Give an error message
} else {
// Continue with the rest
}
Run Code Online (Sandbox Code Playgroud)
有人可以帮我这个.
你可以这样试试:
@echo off
netstat -o -n -a | findstr ZXCZXCZCZX
if %ERRORLEVEL% equ 0 (@echo "port taken")
ELSE (@echo "port available")
Run Code Online (Sandbox Code Playgroud)
如果找不到项目,FINDSTR将返回%ERRORLEVEL%> 0
(在Windows 7 64位的命令控制台上测试)