Jump to content

Script freezes


Recommended Posts

Hey Guys, thanks for the help so far. It was clear that the issue was indeed caused how the DOS command was called. Last night I found a different approach to get the output and has been running all night for almost 10 hours doing 35.000 loops 😁 So this seems more stable :hyper:

It's maybe not a realy nice solution because it just write output to a temp file and reading that. But it does work. What do you think @Nine & @careca ?

#include "Date.au3"
#include "Process.au3"

Opt("TrayIconDebug", 1) ; Debugging info on Systray hover

Main()

Func Main()

    Local Static $mCount = 0

    While 1
        ConsoleWrite("CheckRassdial() = " & CheckRasdial("AlwaysOn-DeviceTunnel"))
        Sleep (1000)

        $mCount += 1
        ConsoleWrite(" --> Looped " & $mCount & " times @ " & _NowCalc() & @CRLF & @CRLF)
    WEnd

EndFunc

Func CheckRasdial($Service)

    _RunDOS('rasdial > ' & @TempDir & "/" & $Service)
    Local $Con = FileRead(@TempDir & "/" & $Service)
    FileDelete(@TempDir & "/" & $Service)

    If StringInStr($Con, $Service) Then Return True

    Return False

EndFunc ;==>CheckRasdial

 

Link to comment
Share on other sites

I'm glad with anything that works for you, specially if the OP came up with the solution by himself. I love that.

That being said, to continuously write, read and delete a file seems like unnecessary overhead, and would prefer a more efficient approach tbh.

Spoiler

Renamer - Rename files and folders, remove portions of text from the filename etc.

GPO Tool - Export/Import Group policy settings.

MirrorDir - Synchronize/Backup/Mirror Folders

BeatsPlayer - Music player.

Params Tool - Right click an exe to see it's parameters or execute them.

String Trigger - Triggers pasting text or applications or internet links on specific strings.

Inconspicuous - Hide files in plain sight, not fully encrypted.

Regedit Control - Registry browsing history, quickly jump into any saved key.

Time4Shutdown - Write the time for shutdown in minutes.

Power Profiles Tool - Set a profile as active, delete, duplicate, export and import.

Finished Task Shutdown - Shuts down pc when specified window/Wndl/process closes.

NetworkSpeedShutdown - Shuts down pc if download speed goes under "X" Kb/s.

IUIAutomation - Topic with framework and examples

Au3Record.exe

Link to comment
Share on other sites

39 minutes ago, careca said:

I'm glad with anything that works for you, specially if the OP came up with the solution by himself. I love that.

That being said, to continuously write, read and delete a file seems like unnecessary overhead, and would prefer a more efficient approach tbh.

Thanks! But programming is not my daily job. I basically search and adapt 😉 That's why I like it AutoITscipt so much. Especially it's function descriptions with the example code. It is very complete and easy to understand (and to adapt).

I do agree with you on unnecessary disk ops. I will think about this too!

Link to comment
Share on other sites

Ok, new approach. It's based on the first script but without the looping. It is unnecessary for my purpose anyway. Maybe that looping caused the issue in the first place.

I will let it run and see what happens.

#include "Date.au3"
#include "Process.au3"

Opt("TrayIconDebug", 1) ; Debugging info on Systray hover

Main()

Func Main()

    Local Static $mCount = 0

    While 1
        ConsoleWrite("UserTunnel Up = " & CheckRasdial("AlwaysOn-UserTunnel") & @CRLF)
        ConsoleWrite("DeviceTunnel Up = " & CheckRasdial("AlwaysOn-DeviceTunnel"))
        Sleep (1000)

        $mCount += 1
        ConsoleWrite(" --> Looped " & $mCount & " times @ " & _NowCalc() & @CRLF & @CRLF)
    WEnd

EndFunc

Func CheckRasdial($Service)

    Local $iPID = Run(@ComSpec & " /c " & 'rasdial', "", @SW_HIDE, $STDOUT_CHILD)
    ProcessWaitClose($iPID)
    Local $sOutput = StdoutRead($iPID)

    If StringInStr($sOutput, $Service) Then Return True

    Return False

EndFunc ;==>CheckRasdial

 

Link to comment
Share on other sites

Ok I have been testing out @careca idea (to keep the stream open) with a bit of adjustments.  Now it seems to work fine, giving time (some sleep before read) to the command to be executed correctly.  So far no error, after 600 loops, you may want to test it @amu0373.

#include "Date.au3"
#include <WinAPIConv.au3>

Opt("TrayIconDebug", 1)
Opt("MustDeclareVars", 1)

HotKeySet("{ESC}",_Exit)

Main()

Func Main()
  Local Static $mCount = 0
  Local $iRun
  $iRun = Run("cmd.exe", '', @SW_HIDE, $STDIN_CHILD + $STDERR_MERGED)
  ReadStream($iRun)
  While 1
    CheckRasdial($iRun)
    Sleep(500)
    $mCount += 1
    ConsoleWrite(" --> Looped " & $mCount & " times @ " & _NowCalc() & @CRLF)
  WEnd
EndFunc   ;==>Main

Func CheckRasdial($iRun)
  StdinWrite($iRun, 'rasdial' & @CRLF)
  Local $line = ReadStream($iRun)
  ConsoleWrite('$line: ' & $line & @CRLF)
EndFunc   ;==>CheckRasdial

Func ReadStream($iPID)
  Local $vData, $sStream
  Do
    Sleep(200)
    $vData = StdoutRead($iPID)
    If @error Then
      StdioClose($iPID)
      ProcessClose($iPID)
      Exit ConsoleWrite("[ERROR]" & @error & " / " & @extended & @CRLF)
    EndIf
    ;ConsoleWrite($vData & @CRLF)
    $sStream &= $vData
  Until $vData = ""
  Return _WinAPI_OemToChar($sStream)
EndFunc   ;==>ReadStream

Func _Exit ()
  Exit
EndFunc

I don't know the exact reason of the freeze, but I believe there were some clashes between Read/Write.  Letting some time to complete execution of the command has resolved the problem,,,I think.

Link to comment
Share on other sites

3 hours ago, Nine said:

Ok I have been testing out @careca idea (to keep the stream open) with a bit of adjustments.  Now it seems to work fine, giving time (some sleep before read) to the command to be executed correctly.  So far no error, after 600 loops, you may want to test it @amu0373.

3

I will try it because to me it also sounds like a good idea to keep the stream open instead of closing it. However... My latest version of the script in my last post has been running for hours now, doing 8K+ loops. So it seems also stable and it is a lot less complicated.

But I really do appreciate you guys helping me out, so I will play around with the script you both came up with just to figure out how it works and if I can optimize it. I really appreciate you both put in the time to help me out.

Because the result is that my freeze issue is solved! 🤩

Link to comment
Share on other sites

Just to wrap up this thread. Function below to check Rasdial is absolutely stable. It has run for a week without any issue.

Thanks @Nine & @careca for helping me out!

#include "Date.au3"
#include "Process.au3"

Opt("TrayIconDebug", 1) ; Debugging info on Systray hover

Main()

Func Main()

    Local Static $mCount = 0

    While 1
        ConsoleWrite("UserTunnel Up = " & CheckRasdial("AlwaysOn-UserTunnel") & @CRLF)
        ConsoleWrite("DeviceTunnel Up = " & CheckRasdial("AlwaysOn-DeviceTunnel"))
        Sleep (1000)

        $mCount += 1
        ConsoleWrite(" --> Looped " & $mCount & " times @ " & _NowCalc() & @CRLF & @CRLF)
    WEnd

EndFunc

Func CheckRasdial($Service)

    Local $iPID = Run(@ComSpec & " /c " & 'rasdial', "", @SW_HIDE, $STDOUT_CHILD)
    ProcessWaitClose($iPID)
    Local $sOutput = StdoutRead($iPID)

    If StringInStr($sOutput, $Service) Then Return True

    Return False

EndFunc ;==>CheckRasdial

 

Link to comment
Share on other sites

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...