I have a program Scheduler.exe which acts like a server for certain processing.
I want to have a php program which can check if this program is running and if not, start it.
I also need a php program which can stop it likewise.
I am running the program in Windows. Is there any possible way to do this?
need help in getting processes list
Moderator: General Moderators
Re: need help in getting processes list
Hi,
hmm. I think there is no DOS command for listening the running processes. So you have to write a second program which lists you the running processes.
After that, you can check the output of this programm and starting your schedule.exe.
Unter Linux this would be much easier, because you just have to call 'ps' in php, then starting the programm (with 'schedule &') and killing it by 'kill schedule' or 'kill PID'.
hmm. I think there is no DOS command for listening the running processes. So you have to write a second program which lists you the running processes.
After that, you can check the output of this programm and starting your schedule.exe.
Unter Linux this would be much easier, because you just have to call 'ps' in php, then starting the programm (with 'schedule &') and killing it by 'kill schedule' or 'kill PID'.
Re: need help in getting processes list
Hi, after going through the post, i realized there is no way i can do it directly by php. So i wrote two batch files which will do that work and am simply doing an exec on them.
Here is the sample code if it might help any one. to start the server:
This will start the server and if already running, it will just ignore and return back.
Now to stop the server:
This has worked for me quite well.. except that when i call the php to start server, it will not be able to return me anything first time since it executes forever. This problem i solved by just putting an alert to the user that if there is no response for five seconds, just stop in browser and retry. 
Here is the sample code if it might help any one. to start the server:
Code: Select all
tasklist /FI "IMAGENAME eq SMSScheduler.exe" /FO CSV > search.log
FOR /F %%A IN (search.log) DO IF %%~zA EQU 0 GOTO end
CD "E:\Naresh\java\SMSScheduler\SMSScheduler\bin\Release" //location of the exe file
e:
start SMSScheduler.exe serverconfig.xml //command to execute the program
:end
del search.log
EXIT
Now to stop the server:
Code: Select all
tasklist /FI "IMAGENAME eq SMSScheduler.exe" /FO CSV > search1.log
FOR /F %%A IN (search.log) DO IF %%~zA EQU 0 GOTO end
@echo off
TASKKILL /F /IM "SMSScheduler.exe" //name of the process to look into
:end
del search1.log