Jump to content

Run() Freezing After Looping 43 Times


Recommended Posts

Hello, I'm running into an issue with the Run() command. I'm calling it from within two loops and it semi randomly freezes. It usually works though if I limit the inner loop to only run 43 times (yes, 43, not 44). I'm rather lost and confused about it. Maybe it's just a limitation that I don't know about. I even tried adding a wait(5000) every 10 loops, but it still freezes.

The scenario that I'm testing this involves the user selecting a folder which contains multiple subfolders. Each subfolder has numerous xml files in it.

/Root

3 Folders

/Root/Subfolder1

253 xml Files

/Root/Subfolder2

91 xml files

/Root/Subfolder3

31 xml files

Populating column 1 and 2 work fine, but column 3 is the result of calling _password(). The function is in xpath.au3 and it's that function which is causing me troubles.

I'd greatly appreciate any help, this is my first autoit script and I did try and research this problem.

I found the LimitsDefaults list in the documentation and I'm not certain from reading that if I'm reaching one of them.

An oddity that is worth pointing out is, there is two loops, and if parent loop can run 3 times (one for each subfolder) and as long as the inner is set to only run 43, all 3 parent loops work like a charm.

Main Script

#include <File.au3>
#include <Array.au3>
#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <GUIListBox.au3>
#include <WindowsConstants.au3>
#include <ProgressConstants.au3>
#include <xpath.au3>

$mainwindow = GUICreate("Form1", 789, 646, 192, 124)
$Openbtn = GUICtrlCreateButton("Open", 32, 8, 97, 25)
$listview = GUICtrlCreateListView("Server              |Channel Name                      |Password  ", 24, 72, 737, 539)
$Progress1 = GUICtrlCreateProgress(144, 8, 617, 25)
GUISetState(@SW_SHOW)


While 1
    $nMsg = GUIGetMsg()
    Select
        Case $nMsg = $GUI_EVENT_CLOSE
            Exit
         Case $nMsg = $Openbtn
            $OpenDialog = FileSelectFolder ("Select Mirth Root", @WorkingDir)
            if @error Then
               MsgBox(4096,"","No folder chosen")
            Else
               $OpenDialog = StringReplace($OpenDialog, "|", @CRLF)
               $FileListArray = _FileListToArray($OpenDialog,"*",2)
               For $i = 1 To $FileListArray[0]
                  $directory = $OpenDialog & "\" & $FileListArray[$i]

                  $subfilesArray = _FileListToArray($directory, "*.xml")

                    ;Run() doesn't freeze if I change the loop to stop at 43. And it'll run through the parent loop multiple times still.
                    ;For $a = 1 To 43

                    For $a = 1 to $subfilesArray[0]
                        $file= $directory & "\" & $subfilesArray[$a]
                        $password = _password($file)
                        GUICtrlCreateListViewItem($a & " " & $FileListArray[$i] & "|" & StringReplace($subfilesArray[$a],".xml","") & "|" & $password ,$listview)
                    Next             
               Next
            EndIf
    EndSelect
WEnd

xpath.au3

#include <Constants.au3> 
#include <Process.au3>

Func _password($file)

$cmds = "sel -t -v //property[@name='password'][last()] " & """" & $file & """"

Local $foo = Run(@WorkingDir & "\xml.exe " & $cmds, @SystemDir, @SW_HIDE, $STDERR_CHILD + $STDOUT_CHILD) 

;This script still freezes even if I'm not running xml.exe ("echo hi" for example). It freezes after 43 runs on JUST the innerloop from the main au3.
;Local $foo = Run(@ComSpec & " /c echo hi", @SystemDir, @SW_HIDE, $STDERR_CHILD + $STDOUT_CHILD) 

Local $line

While 1 
$line &= StdoutRead($foo) ; change 1 
If @error Then ExitLoop 

Wend 


While 1 
$line &= StderrRead($foo) ; change 2 
If @error Then ExitLoop 
Wend 
   return $line
EndFunc
Edited by mrkyle
Link to comment
Share on other sites

I don't see anything right off that would cause the problem. The application thats being executed could be the problem or pherhaps is the way your looping through. I would first try ShellExecute in place of run. I'd double check my array bounds and add lines for debug - ConsoleWrite the index and array bounds. Be sure to search to forum for UDFs that lists files/folders recursively so you have something to compare against. Melba32 usually has a script or two for that in his sig.

*Edit - Use comspec(<-- check the Run function help docs) to execute the xml.exe

Edited by Decipher
Spoiler

censored.jpg

 

Link to comment
Share on other sites

  • Moderators

mrkyle,

Melba23 certainly does have something to list files recursively - look at RecFileListToArray in my sig. ;)

M23

Edit:

I have just run your script (less the _password function as I do not have xml.exe) and the inner loop ran up to 400 times without any problem. The only thing I can think of is that you are running multiple instances of xml.exe concurrently (i.e they never actually close) and so bumping into some Windows limit on the number of child processes you can spawn - can you check in Task Manager to see if this is the case? If it is then a ProcessClose($foo) at the end of _password should do the trick. ;)

Edited by Melba23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

(sorry, spoke too soon about it working again.)

Melba23, thanks for the input. I changed the _password function to just use echo instead of run xml. I'm curious to know if you run into the same problem that I do.

I'll have to go through RecFileListToArray and see how I can adapt it -- at the very least just try something different.

Thanks guy!

#include <Constants.au3> 
#include <Process.au3>

Func _password($file)

$cmds = "sel -t -v //property[@name='password'][last()] " & """" & $file & """"


;Local $foo = Run(@ComSpec & " /c " & @WorkingDir & "\xml.exe " & $cmds, @SystemDir, @SW_HIDE, $STDERR_CHILD + $STDOUT_CHILD) 

;This script still freezes even if I'm not running xml.exe ("echo hi" for example). It freezes after 43 runs on JUST the innerloop from the main au3.
Local $foo = Run(@ComSpec & " /c echo hi", @SystemDir, @SW_HIDE, $STDERR_CHILD + $STDOUT_CHILD) 

Local $line

While 1 
$line &= StdoutRead($foo) ; change 1 
If @error Then ExitLoop 

Wend 


While 1 
$line &= StderrRead($foo) ; change 2 
If @error Then ExitLoop 
Wend 
   ProcessClose($foo)
   return $line
EndFunc
Edited by mrkyle
Link to comment
Share on other sites

  • Moderators

mrkyle,

Running the script with another set of files still gave me well over 43 returns from a couple of subfolders - but did bring up one error situation. You do not test to see if there are any files in the subfolder before accessing the return from _FileListToArray. If there are no matching files, you will get an error as you try to access a non-existent array - just add some error-checking like this: ;)

$subfilesArray = _FileListToArray($directory, "*.au3")
    If Not @error Then
        ;Run() doesn't freeze if I change the loop to stop at 43. And it'll run through the parent loop multiple times still.
        ;For $a = 1 To 43
        For $a = 1 To $subfilesArray[0] ; This will crash if there is no array returned <<<<<<<<<<<<<<<<<<
            $file = $directory & "\" & $subfilesArray[$a]
            $password = _password($file)
            GUICtrlCreateListViewItem($a & " " & $FileListArray[$i] & "|" & StringReplace($subfilesArray[$a], ".xml", "") & "|" & $password, $listview)
        Next
    Else
        ; This is just to see if you ever run across the problem <<<<<<<<<<<<<<<<<<<<<<<<<<<<
        MsgBox(0, "Hi", "Nothing found in " & $directory)
EndIf

Hoever, I do not think this is the cause of your looping problem as it gives a hard fail when it occurs. :(

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

I get more than 43 results if I have multiple subfolders. For whatever reason the parent loop works fine, but the inner loop crashes if a subfolder has more than 43 xml files.

Thanks for the tip about error checking, this was my first script, so I'm a bit fuzzy on good coding conventions (I'm not a developer, I'm an implementation engineer).

So did you run into freezing troubles when you ran it? Say, when a subfolder has 80 files in it?

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...