Answer the question
In order to leave comments, you need to log in
Why is the variable sometimes empty?
Hello, please tell me, there is a script for autoit that checks every 30 seconds that the program is connected over the network, everything works fine, but sometimes at random time, it can be 5 minutes, or maybe several hours or several minutes, the $str variable turns out to be empty, as if the program is no longer connected over the network and the program is restarted, but in fact the program does not lose connection and continues to work, how can I fix such a bug and what could be the problem ?
Func timer()
Sleep(30000) ; 30 sec
qry()
EndFunc
Local $str = ''
Local $pid = Run(@ComSpec & " /c " & 'netstat -a -n | findstr ":80"', '', @SW_HIDE, 2)
While ProcessExists($pid)
$str &= StdoutRead($pid)
WEnd
if $str Then
_DebugOut (_NowTime() & ": Процесс активен")
timer()
Else
_DebugOut (_NowTime() & ": Процесс не активен")
Start()
EndIf
Answer the question
In order to leave comments, you need to log in
Searching findstr ":80" in netstat means that it is looking for information that a certain program has opened a connection either from port 80 or port 80. And this can be a browser, and some running program, and even Windows auto-update. Some too general rule you got.
In addition, the connection of your program cannot be eternal, connections tend to be interrupted, for technical reasons. And it all depends on how quickly the program restores the connection, if it restores it at all. If the script hits a moment when the connection is not restored, then there will be an empty result. The simplest thing is to do a second check after, for example, 10 seconds, and if there is still no connection, then do a (re)start.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question