@echo off
:: 进入服务的应用程序的路径
cd /d C:\MachineControl\mc-api
:: 以最小化窗口启动启动mc服务
start /min dotnet AM.MC.WebApi.dll --urls http://*:8081
echo mc-api is running...
:: 进入服务的应用程序的路径
cd /d C:\MachineControl\mcm-api
:: 以最小化窗口启动启动mcm服务
start /min dotnet AM.Mcm.WebApi.dll --urls http://*:8082
echo mcm-api is running...
:: 暂停以查看输出
pause
Start.bat --服务已经运行时,先关闭在开启
@echo off
setlocal EnableDelayedExpansion
REM Define port number as a variable
set "PORT=8081"
REM Check if the service is already running
set found=0
REM Create a temporary file to track processed PIDs
set "temp_file=%TEMP%\processed_pids.tmp"
if exist "%temp_file%" del "%temp_file%"
echo Checking for existing processes on port %PORT%...
for /f "tokens=5" %%a in ('netstat -ano ^| findstr "LISTENING" ^| findstr ":%PORT%" 2^>nul') do (
if %%a NEQ 0 (
REM Check if we've already processed this PID
findstr /C:"%%a" "%temp_file%" >nul 2>&1
if !errorlevel! NEQ 0 (
echo Found process: %%a using port %PORT%
echo %%a >> "%temp_file%"
taskkill /F /PID %%a 2>nul
if !errorlevel! equ 0 (
echo Successfully stopped process %%a
set found=1
) else (
echo Warning: Could not terminate process %%a
)
)
)
)
REM Clean up temp file
if exist "%temp_file%" del "%temp_file%"
if !found! equ 0 (
echo No existing process found on port %PORT%
) else (
echo Waiting for port to be released...
timeout /t 3 > nul
REM Verify port is free
netstat -ano | findstr "LISTENING" | findstr ":%PORT%" >nul 2>&1
if !errorlevel! equ 0 (
echo Warning: Port %PORT% is still in use. Continuing anyway...
) else (
echo Port %PORT% is now free
)
)
REM Start the service
echo Starting service...
dotnet AM.MC.WebApi.dll --urls http://*:%PORT%