0

So this bat file was running perfectly right before this latest windows update.

@Echo off
:Start
Start E:\directoryhere?listen -dedicated
echo Press Ctrl-C if you don't want to restart automatically
ping -n 10 localhost
goto Start

So this would start a dedicated server. A command prompt would pop up. When everyone left the server or the game finished, the command prompt would close then the .bat file would reopen it. Now after this update, the .bat file just keeps opening the cmd prompt while its open. So i'll have instantly 20 instances open at once and my cpu is at 100%.

I've also had this code before the windows update before this one which ended up doing the same thing.

@echo off
cd "E:\directoryhere\"
:loop
Start RxGame-Win64-Test.exe server lv_canyon?listen -dedicated | set /P "="
goto loop

That code used to work, but 2 window updates before ended up doing the same thing. It would just keep opening instances and make my cpu 100%.

What's a way to make sure to see if the cmd prompt is open and not to reopen it and keep it running until the cmd prompt closes then reopen it.

  • Why are you making a loop? That's kinda your issue here. – John Kens Jan 03 '19 at 05:15
  • Well I was originally looking for something to restart a program. The server goes down when everyone leaves and doesn't start up. So I found the .bat that will loop it if it goes down. It has worked for months until the last couple window updates. That's why I'm looking for another solution ATM which has been found. – King Tomato Jan 04 '19 at 13:18

1 Answers1

0

A simple fix to this can to check is the process already is open first using tasklist. Please make sure you search what your actual application is called. For this example I'm going to guess it's called RxGame-Win64-Test.exe. Bellow are a few script options.

This script bellow will check to see if the RxGame-Win64-Test.exe app is open first before starting another one:

@ECHO OFF
@SETLOCAL enabledelayedexpansion
GOTO LOOP

:LOOP

Rem | Check If Window Is Open
tasklist /FI "IMAGENAME eq RxGame-Win64-Test.exe" 2>NUL | find /I /N "RxGame-Win64-Test.exe">NUL
if not "%ERRORLEVEL%"=="0" (

    Rem | Process Not Found
    timeout /T 10 /NOBREAK

    Rem | Restart Server
    start "" "RxGame-Win64-Test.exe server lv_canyon?listen -dedicated"

    Rem | GOTO LOOP
    GOTO LOOP

)

GOTO LOOP

Not sure if the RxGame-Win64-Test.exe is CMD based program or not but if it is the script bellow will help you:

@ECHO OFF
@SETLOCAL enabledelayedexpansion

Rem | First Load, Start Server
start "DedicatedServerLauncher" cmd /c "RxGame-Win64-Test.exe server lv_canyon?listen -dedicated"

GOTO LOOP

:LOOP

Rem | Reset PID
Set "PID="

Rem | Grab The Current Window PID
FOR /F "tokens=2" %%# in ('tasklist /v ^| find "DedicatedServerLauncher" ^| find "Console"') do set PID=%%#

Rem | Check If Window Is Open
if "!PID!"=="" (

    Rem | Process Not Found
    timeout /T 10 /NOBREAK

    Rem | Restart Server
    start "DedicatedServerLauncher" cmd /c "RxGame-Win64-Test.exe server lv_canyon?listen -dedicated"

    Rem | GOTO LOOP
    GOTO LOOP
)

GOTO LOOP

For help on any of the commands do the following:

  • call /?
  • set /?
  • for /?
  • if /?
  • find /?
  • So on.
John Kens
  • 1,615
  • 2
  • 10
  • 28
  • I appreciate it! The first .bat commands gave an error of not RxGame-Win64-Test.exe not being found. But the second one you mentioned, it worked perfectly. Thank you! – King Tomato Jan 03 '19 at 21:52
  • @KingTomato If the answer was a solution to your question, please consider clicking the green check-mark to accept this response as a solution. This helps not only me but lets others who explore the site know this will fix there issue. – John Kens Jan 03 '19 at 23:24