goodbyeplanet Posted January 13, 2011 Author Posted January 13, 2011 Let's try thinking about this a different way. Your goal of a program like this is...1. Check to make sure HTTPD is running.2. If not running - start it.3. If HTTPD could not start, notify/log.Correct?here is my psuedocode1). check to make sure apache is running2). if not, then start apache using run command.3). if run command fails to start apache then log results.
ZacUSNYR Posted January 13, 2011 Posted January 13, 2011 Look at Varians code, should do exactly what you need I started to write something similar but he's mucho quicker then me. Same concept I was chasing, you don't need to verify it starts, you need to check to see if it's running after starting it.
Varian Posted January 13, 2011 Posted January 13, 2011 ok here is what i have done. Maybe if somebody tells me why the msgbox output gives a result of o on the first run of the loop then i might somehow figure out my way forward. However on the second run of the loop the msgbox displays that apache has started. why is it like this. i am expecting that the run statement will start apache then wait for 2500 and give apache time to start then if it hits the second if statement i expect that the value of $apache will change since apache would have been started already. First run: ProcessExists() returns 0 because the Process does not exist Start the program, which starts the ProcessSecond run: ProcessExists() returns PID because the Process existsThis is exactly what is supposed to happen
goodbyeplanet Posted January 13, 2011 Author Posted January 13, 2011 First run: ProcessExists() returns 0 because the Process does not exist Start the program, which starts the ProcessSecond run: ProcessExists() returns PID because the Process existsThis is exactly what is supposed to happenbut look closely at my script it starts the process then wait for some seconds(waiting for the process to start) then when it hits the second if statement its still 0....does it mean that if a process starts and then test the variable before the script loops it will still be always 0 even if the process has started???
Varian Posted January 13, 2011 Posted January 13, 2011 (edited) but look closely at my script it starts the process then wait for some seconds(waiting for the process to start) then when it hits the second if statement its still 0....does it mean that if a process starts and then test the variable before the script loops it will still be always 0 even if the process has started??? $Apache is still 0 because you never re-evaluated it again..I think this is what you meant to doWhile 1 $Apache = ProcessExists("httpd.exe") If $Apache = 0 Then Run(@ComSpec & " /c " & 'net start wampapache', "", @SW_HIDE) Sleep(2500) $Apache = ProcessExists("httpd.exe") ;Here, I checked Apache again, otherwise it would still be the same If $Apache = 0 Then MsgBox(4096, "", $Apache) EndIf EndIf WEnd EDIT: Take note, that if $Apache is not 0, the message box WILL NOT display Edited January 13, 2011 by Varian
goodbyeplanet Posted January 13, 2011 Author Posted January 13, 2011 (edited) thanks Verian for your help..i have seen your script and I have seen how you have used the Do..until statement. i have tried it and i am happy and very grateful for your help but for the sake of learning programming i still cannot understand why i get a zero on the script i posted before even after i have started the process and waited to make sure that the process starts. otherwise thank you every one for your help...love u lots... Edited January 13, 2011 by goodbyeplanet
goodbyeplanet Posted January 13, 2011 Author Posted January 13, 2011 Read my previous post to understandja thanks i posted before i saw your post..thanks Varian
BrewManNH Posted January 13, 2011 Posted January 13, 2011 (edited) You're only checking to see if Apache is running once in the script. The second If statement is always going to be the same as the first If statement because of this. If you want to check to see if it's running after you start it with the Run command, you'll need to add a second $apache = ProcessExists("httpd.exe") statement after the sleep. Edit: Didn't see it had gone to page 2 already Edited January 13, 2011 by BrewManNH If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag GudeHow to ask questions the smart way! I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from. Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator
goodbyeplanet Posted January 13, 2011 Author Posted January 13, 2011 You're only checking to see if Apache is running once in the script. The second If statement is always going to be the same as the first If statement because of this. If you want to check to see if it's running after you start it with the Run command, you'll need to add a second $apache = ProcessExists("httpd.exe") statement after the sleep.Edit: Didn't see it had gone to page 2 already thanks soo much BrewManNH for your explnation.. Now I have learnt something today. yes its now 2 pages:) but thanks all for your patience..
Newb Posted January 13, 2011 Posted January 13, 2011 now that script doesnt work, i tried it beforeJust a useless punctualization, but then u can do the same thing you did in the script I tried to correct by using ElseIf instead of Else I'm a compulsive poster. When I post something, come to read it at least 5 minutes later after the posting, because I will edit it. I edited even this signature a few minutes later after I wrote it.
goodbyeplanet Posted January 13, 2011 Author Posted January 13, 2011 ok before i go to sleep i thought i would share my final script. I have tested it and i am happy. basically it brings together all the suggestions u brought out...I have increased the sleeping time so that it doesnt quickly fill up the log file. here it is below. #include <file.au3> While 1 $sLogPath = ("c:\apachelog.txt") $sLogMsg1 = ("apache server started ") $sLogMsg2 = ("fatal error - script failed to start apache server") $Apache = ProcessExists("httpd.exe") If $Apache = 0 Then Run(@ComSpec & " /c " & 'net start wampapache', "", @SW_HIDE) Sleep(9500) _FileWriteLog($sLogPath, $sLogMsg1 ) $Apache = ProcessExists("httpd.exe") If $Apache = 0 Then _FileWriteLog($sLogPath, $sLogMsg2 ) EndIf EndIf WEnd
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now