Page 1 of 1
Help please
Posted: 02 Jan 2010 23:20
by The Great One
I need some help I can't get this to work. I am trying to write a batch that will check for a specific process. If the process is running it will check it again and if the process is off it will start it. Here is what i have so far but i keep getting a generic error.
@echo off
:THERE
Start chrome.exe
:HERE
tasklist /fi "STATUS eq chrome.exe" >nul
If errorlevel 1 goto THERE else goto HERE
pause
Posted: 04 Jan 2010 15:48
by avery_larry
What is the generic error?
Posted: 04 Jan 2010 16:04
by viroid
I was under the impression that if ELSE was used with IF then it needed to be formatted with parrenthesis...
IF ERRORLEVEL 1 (DO ONE) ELSE (DO TWO)
IF ERROR LEVEL 1 (
DO ONE
)
ELSE
(
DO TWO
)
Also, I've had issues using GOTO statements within if statements. I've often done something like ECHO. & GOTO HERE in order to get it to work correctly because it wouldn't work with just a GOTO HERE.
Posted: 04 Jan 2010 18:45
by The Great One
Thanks for replying. I tried to use the parenthesis but it did not help. It keeps giving me infinite generic errors. I wonder if there is a different way to code it? All I want it to do is reopen a program every time it is closed.
p.s. I'm new to dos coding.
Posted: 05 Jan 2010 08:01
by !k
The Great One
I have a Russian M$ "Windows", so I do not know, really need to look for "Running" or another word. Check it before use, otherwise you bury surf windows
Code: Select all
@echo off
:nono
tasklist /v /fi "imagename eq calc.exe" 2>nul |findstr "Running" >nul ||start calc.exe
goto :nono
Or, if you do not need to check the Hanging application, then simply write:
Code: Select all
@echo off
:load
tasklist |findstr "calc.exe" >nul ||start calc.exe
goto :load
Posted: 05 Jan 2010 16:37
by viroid
I just attempted to perform a similar function using TASKLIST, it didn't appear to return a different errorlevel when the filter found the task.
Posted: 05 Jan 2010 16:46
by The Great One
Thanks for all your help guys. It works now using !k's code
@echo off
:nono
tasklist /v /fi "imagename eq calc.exe" 2>nul |findstr "Running" >nul ||start calc.exe
goto :nono
I did post another topic that has not been answered so any help with that would be appreciated too.
Posted: 05 Jan 2010 17:35
by viroid
I got it working using FOR ...
:LOOP
FOR /F "skip=3 usebackq tokens=1" %%i in (`TASKLIST /FI "IMAGENAME eq CALC.EXE"`) DO (
IF NOT "%%i"=="" Echo Process is Running
SLEEP 1
)
GOTO LOOP