Checking if the application is running from a batch file?

How do I use a batch file to check if the application is still working? If the application is still running, this process will be repeated over and over. Otherwise, an error message will appear.

Many thanks

+1


source to share


4 answers


on windows you use pstools pslist to check if the process name is running with a .cmd script like below. Pslist will return ERRORLEVEL 0 if the process is running, 1 if not.



@echo off

CommandYouWillRun.exe

rem waiting for the process to start
:startcmd
sleep 1
c:\path\to\pslist.exe CommandYouWillRun > NUL
IF ERRORLEVEL 1 goto startcmd

rem the process has now started

:waitforcmd
sleep 1
c:\path\to\pslist.exe CommandYouWillRun > NUL
IF ERRORLEVEL 1 got finished
goto waitforcmd

:finished
echo "This is an error message"

      

+5


source


Linux?

ps aux | Grep task | wc -l



where task is the name of the task (for example, "apache2" - no quotes needed)

+2


source


You can write powershell-script and use get-process with filtering.

http://www.computerperformance.co.uk/powershell/powershell_process.htm

+1


source


Perhaps you mean a task list? You can run this from the command line to get all running processes on Windows ... for the rest of what you're asking, I think you need to be more specific.

0


source







All Articles