根据进程名称或PID查看相应的进程是否存在:
@echo off
set /p processStr=Please enter your process name or PID:
for /f "delims=" %%i in ('tasklist ^| findstr "%processStr%"') do set str=%%i
echo %str%
echo %str%|findstr "%processStr%" > nul
if %errorlevel% equ 0 (
echo The "%processStr%" process exists.
) else (
echo The "%processStr%" process doesn't exist.
)
pause
查看端口是否被其他进程占用:
@echo off
set /p portStr=Please enter your port:
for /f "delims=" %%i in ('netstat -ano ^| findstr "%portStr%"') do set str=%%i
echo %str%
echo %str% | findstr "%portStr%" > nul && (
echo The "%portStr%" port exists.
) || (
echo The "%portStr%" port doesn't exist.
)
pause