bat运行netcore

@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%

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值