mrkyle Posted March 30, 2013 Posted March 30, 2013 (edited) 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 expandcollapse popup#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 March 30, 2013 by mrkyle
Decipher Posted March 30, 2013 Posted March 30, 2013 (edited) 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 March 30, 2013 by Decipher Spoiler
Moderators Melba23 Posted March 30, 2013 Moderators Posted March 30, 2013 (edited) mrkyle,Melba23 certainly does have something to list files recursively - look at RecFileListToArray in my sig. M23Edit: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 March 30, 2013 by Melba23 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 columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area
mrkyle Posted March 30, 2013 Author Posted March 30, 2013 (edited) (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 March 30, 2013 by mrkyle
Moderators Melba23 Posted March 30, 2013 Moderators Posted March 30, 2013 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) EndIfHoever, I do not think this is the cause of your looping problem as it gives a hard fail when it occurs. M23 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 columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area
mrkyle Posted March 30, 2013 Author Posted March 30, 2013 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?
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