I am trying to restart a service if a particular command line program hangs / gives out error. The program, if successful will give out(into stdout ) "Host ....."
What i had come with is on the "code segment".
I use "Set objExecObject = objShell.Exec(strCommand)"
to call the program.
(Where strCommand in this case is err.exe which just prints the key word into the stdout/stderr . it prints "Error: asdfasf" or "Host .................." . I edit the program and rebuild it every time as per the requirement. )
But the problem is, if the program(err.exe) hangs, it will not execute the next line rather it waits for the program finishes.
In reality the program i would be using is fusping (a Cyberfusion custom program to test the server)
key word to look for = "Error :"
a reverse logic can be to look for the Keyword "Host"
if the program hangs : Nothing comes out. and waits
Can any one help me to bypass this issue.
OS : win 2k server ( I think it should work on any thing from win 2k / xp )
Dim intShortSleep, intLongSleep, strService
dim objShell, objExecObject, strOutput
strService = "Messenger" ' Messenger is just an example'
intShortSleep = 5000
intLongSleep = 15000 '1000 = 1 second '
strCommand = "err" ' err is just an exe , made using a C program, in reality , it will be fusping of cyberfusion '
Msgbox intFound & " Before the loop ... clear it " ' Just a message box to test the looping can ignore this'
Do Until intFound =0
Msgbox intFound & " Inthe loop ..Clear it"
Msgbox "bye" ' Remove before implimentation'
Set objShell = WScript.CreateObject("WScript.Shell")
Set objExecObject = objShell.Exec(strCommand)
Do Until objExecObject.Stdout.AtEndOfStream
strOutput = objExecObject.Stdout.ReadLine()
' syntax : InStr([start,]string1,string2[,compare])'
intFound=intFound + InStr(strOutput,"Error")
' Restart Service'
objShell.Run "net stop " & strService
objShell.Run "net start " & strService