Saturday, April 18, 2015

windows 7 - How do I make a batch file that started a process to wait for the process to terminate?


My computer isn't the best but it does meet the minimal requirments to play GTA V. I wanted to make the game run faster so instead of using the normal .exe, this is the batch file I use to launch the game:


start steam://rungameid/271590
timeout 60
wmic process where name="GTA5.exe" CALL setpriority "high priority"
wmic process where name="gtavlauncher.exe" CALL setpriority "idle"
wmic process where name="subprocess.exe" CALL setpriority "idle"

so basically after launching the game it sets the priorities so only the GTA5.exe runs and the cpu ignores the other processes that come with it.
I wanted it to run even smoother and changing the windows theme to "classic" helps with that, so I downloaded a program that allowes me to change the themes with cmd commands and I made this script-


START c:\ThemeSwitcher classic
start steam://rungameid/271590
timeout 60
wmic process where name="GTA5.exe" CALL setpriority "high priority"
wmic process where name="gtavlauncher.exe" CALL setpriority "idle"
wmic process where name="subprocess.exe" CALL setpriority "idle"
wait process where name="GTA5.exe"
-----------------------------------------------------------
start c:\ThemeSwitcher MY PC

in the "----------" I want to put something that makes the file wait for the processes to terminate before changing the theme to normal, so I don't have to do it manually.
I only know a few batch commands that I used google for, and right now it doesn't help.
sorry for bad english.


Answer



create batch like this:


title i'm waiting
start /wait /high cmd /ktitle kill me
echo This is the end
pause

you can see how work start command with wait parameter


you can create batch with pause, after do something hit space in batch window, then it run next command


you probably looking for something like waiting for terminate existing process:


echo do somthing at start
:start_test
::wait ~6s -1s = 5s
::you can use TIMEOUT 5
call :sleep 6
wmic process where name="notepad.exe" get name |find "notepad.exe">nul
if %errorlevel%==0 goto :start_test
echo do somthing at the end
::pause
goto :eof
:sleep
ping 127.0.0.1 -n %1 > nul
goto :eof

it test process exists every 5s, you can change interval.


No comments:

Post a Comment

linux - How to SSH to ec2 instance in VPC private subnet via NAT server

I have created a VPC in aws with a public subnet and a private subnet. The private subnet does not have direct access to external network. S...