PowerCat Posted February 19, 2011 Share Posted February 19, 2011 (edited) Have I got a challenge for you my friends.I have recreated a scenario from an issue at work. It’s a process for installing software, and I need to break out of a DOS FOR loop Please download the files available here to have everything you need:http://dl.dropbox.com/u/7829694/cut_pkg.zipThe rule is that you can only modify cut_pkg_list.au3. The rest are accurate representation of the environment.Launch list.bat as it, you should see one msgbox for each entry in list.txt and 3 times loop2 msgbox. This is a successful run.Open the backup-list.txt and find the line that says CUTHERE.Paste it anywhere between the other lines in list.txt and run list.bat again.When the loop parses the CUTHERE line, cut_pkg_list.au3 will run.It’ll find where the CUTHERE line is in list.txt and make a new file with whatever followed it. (this is the list of stuff that should not be installed at this time. Break out of the loop and I’ll take care of them at a later time) (this part works. I don’t know why)A successful run should be breaking out of the loop so that the MSGBOX for the lines that followed the CUTHERE are NOT displayed (must not be installed), but the LOOP2 MSGBOX are displayed. This is not working right now.The objective is: Break out of loop1 from list.bat by adding something to to the end of cut_pkg_list.au3 but still succesfully run the second FOR loop in list.batPlease halp! This is quite puzzling.I hope I’m expressing myself correctly. English is not my mother tongue. Edited February 19, 2011 by PowerCat Link to comment Share on other sites More sharing options...
JoHanatCent Posted February 19, 2011 Share Posted February 19, 2011 The FOR /f loop will execute every line from a text file.I'd like for when my script runs, it breaks out of the FOR loop which called the script.How did you start this loop? An example script would speed things up A lOt! Link to comment Share on other sites More sharing options...
guinness Posted February 19, 2011 Share Posted February 19, 2011 ExitLoop UDF List: _AdapterConnections() • _AlwaysRun() • _AppMon() • _AppMonEx() • _ArrayFilter/_ArrayReduce • _BinaryBin() • _CheckMsgBox() • _CmdLineRaw() • _ContextMenu() • _ConvertLHWebColor()/_ConvertSHWebColor() • _DesktopDimensions() • _DisplayPassword() • _DotNet_Load()/_DotNet_Unload() • _Fibonacci() • _FileCompare() • _FileCompareContents() • _FileNameByHandle() • _FilePrefix/SRE() • _FindInFile() • _GetBackgroundColor()/_SetBackgroundColor() • _GetConrolID() • _GetCtrlClass() • _GetDirectoryFormat() • _GetDriveMediaType() • _GetFilename()/_GetFilenameExt() • _GetHardwareID() • _GetIP() • _GetIP_Country() • _GetOSLanguage() • _GetSavedSource() • _GetStringSize() • _GetSystemPaths() • _GetURLImage() • _GIFImage() • _GoogleWeather() • _GUICtrlCreateGroup() • _GUICtrlListBox_CreateArray() • _GUICtrlListView_CreateArray() • _GUICtrlListView_SaveCSV() • _GUICtrlListView_SaveHTML() • _GUICtrlListView_SaveTxt() • _GUICtrlListView_SaveXML() • _GUICtrlMenu_Recent() • _GUICtrlMenu_SetItemImage() • _GUICtrlTreeView_CreateArray() • _GUIDisable() • _GUIImageList_SetIconFromHandle() • _GUIRegisterMsg() • _GUISetIcon() • _Icon_Clear()/_Icon_Set() • _IdleTime() • _InetGet() • _InetGetGUI() • _InetGetProgress() • _IPDetails() • _IsFileOlder() • _IsGUID() • _IsHex() • _IsPalindrome() • _IsRegKey() • _IsStringRegExp() • _IsSystemDrive() • _IsUPX() • _IsValidType() • _IsWebColor() • _Language() • _Log() • _MicrosoftInternetConnectivity() • _MSDNDataType() • _PathFull/GetRelative/Split() • _PathSplitEx() • _PrintFromArray() • _ProgressSetMarquee() • _ReDim() • _RockPaperScissors()/_RockPaperScissorsLizardSpock() • _ScrollingCredits • _SelfDelete() • _SelfRename() • _SelfUpdate() • _SendTo() • _ShellAll() • _ShellFile() • _ShellFolder() • _SingletonHWID() • _SingletonPID() • _Startup() • _StringCompact() • _StringIsValid() • _StringRegExpMetaCharacters() • _StringReplaceWholeWord() • _StringStripChars() • _Temperature() • _TrialPeriod() • _UKToUSDate()/_USToUKDate() • _WinAPI_Create_CTL_CODE() • _WinAPI_CreateGUID() • _WMIDateStringToDate()/_DateToWMIDateString() • Au3 script parsing • AutoIt Search • AutoIt3 Portable • AutoIt3WrapperToPragma • AutoItWinGetTitle()/AutoItWinSetTitle() • Coding • DirToHTML5 • FileInstallr • FileReadLastChars() • GeoIP database • GUI - Only Close Button • GUI Examples • GUICtrlDeleteImage() • GUICtrlGetBkColor() • GUICtrlGetStyle() • GUIEvents • GUIGetBkColor() • Int_Parse() & Int_TryParse() • IsISBN() • LockFile() • Mapping CtrlIDs • OOP in AutoIt • ParseHeadersToSciTE() • PasswordValid • PasteBin • Posts Per Day • PreExpand • Protect Globals • Queue() • Resource Update • ResourcesEx • SciTE Jump • Settings INI • SHELLHOOK • Shunting-Yard • Signature Creator • Stack() • Stopwatch() • StringAddLF()/StringStripLF() • StringEOLToCRLF() • VSCROLL • WM_COPYDATA • More Examples... Updated: 22/04/2018 Link to comment Share on other sites More sharing options...
PowerCat Posted February 19, 2011 Author Share Posted February 19, 2011 (edited) ExitLoop I'm sorry this did not work. The loop is not from autoit. Please download the source files and attempt to resolve the connundrum. There might actually not be a way. Edited February 19, 2011 by PowerCat Link to comment Share on other sites More sharing options...
guinness Posted February 19, 2011 Share Posted February 19, 2011 (edited) The loop is not from autoit.But this is an AutoIt Forum! Edited February 19, 2011 by guinness UDF List: _AdapterConnections() • _AlwaysRun() • _AppMon() • _AppMonEx() • _ArrayFilter/_ArrayReduce • _BinaryBin() • _CheckMsgBox() • _CmdLineRaw() • _ContextMenu() • _ConvertLHWebColor()/_ConvertSHWebColor() • _DesktopDimensions() • _DisplayPassword() • _DotNet_Load()/_DotNet_Unload() • _Fibonacci() • _FileCompare() • _FileCompareContents() • _FileNameByHandle() • _FilePrefix/SRE() • _FindInFile() • _GetBackgroundColor()/_SetBackgroundColor() • _GetConrolID() • _GetCtrlClass() • _GetDirectoryFormat() • _GetDriveMediaType() • _GetFilename()/_GetFilenameExt() • _GetHardwareID() • _GetIP() • _GetIP_Country() • _GetOSLanguage() • _GetSavedSource() • _GetStringSize() • _GetSystemPaths() • _GetURLImage() • _GIFImage() • _GoogleWeather() • _GUICtrlCreateGroup() • _GUICtrlListBox_CreateArray() • _GUICtrlListView_CreateArray() • _GUICtrlListView_SaveCSV() • _GUICtrlListView_SaveHTML() • _GUICtrlListView_SaveTxt() • _GUICtrlListView_SaveXML() • _GUICtrlMenu_Recent() • _GUICtrlMenu_SetItemImage() • _GUICtrlTreeView_CreateArray() • _GUIDisable() • _GUIImageList_SetIconFromHandle() • _GUIRegisterMsg() • _GUISetIcon() • _Icon_Clear()/_Icon_Set() • _IdleTime() • _InetGet() • _InetGetGUI() • _InetGetProgress() • _IPDetails() • _IsFileOlder() • _IsGUID() • _IsHex() • _IsPalindrome() • _IsRegKey() • _IsStringRegExp() • _IsSystemDrive() • _IsUPX() • _IsValidType() • _IsWebColor() • _Language() • _Log() • _MicrosoftInternetConnectivity() • _MSDNDataType() • _PathFull/GetRelative/Split() • _PathSplitEx() • _PrintFromArray() • _ProgressSetMarquee() • _ReDim() • _RockPaperScissors()/_RockPaperScissorsLizardSpock() • _ScrollingCredits • _SelfDelete() • _SelfRename() • _SelfUpdate() • _SendTo() • _ShellAll() • _ShellFile() • _ShellFolder() • _SingletonHWID() • _SingletonPID() • _Startup() • _StringCompact() • _StringIsValid() • _StringRegExpMetaCharacters() • _StringReplaceWholeWord() • _StringStripChars() • _Temperature() • _TrialPeriod() • _UKToUSDate()/_USToUKDate() • _WinAPI_Create_CTL_CODE() • _WinAPI_CreateGUID() • _WMIDateStringToDate()/_DateToWMIDateString() • Au3 script parsing • AutoIt Search • AutoIt3 Portable • AutoIt3WrapperToPragma • AutoItWinGetTitle()/AutoItWinSetTitle() • Coding • DirToHTML5 • FileInstallr • FileReadLastChars() • GeoIP database • GUI - Only Close Button • GUI Examples • GUICtrlDeleteImage() • GUICtrlGetBkColor() • GUICtrlGetStyle() • GUIEvents • GUIGetBkColor() • Int_Parse() & Int_TryParse() • IsISBN() • LockFile() • Mapping CtrlIDs • OOP in AutoIt • ParseHeadersToSciTE() • PasswordValid • PasteBin • Posts Per Day • PreExpand • Protect Globals • Queue() • Resource Update • ResourcesEx • SciTE Jump • Settings INI • SHELLHOOK • Shunting-Yard • Signature Creator • Stack() • Stopwatch() • StringAddLF()/StringStripLF() • StringEOLToCRLF() • VSCROLL • WM_COPYDATA • More Examples... Updated: 22/04/2018 Link to comment Share on other sites More sharing options...
PowerCat Posted February 19, 2011 Author Share Posted February 19, 2011 But this is an AutoIt Forum!the program to break out of the loop is made in autoit Link to comment Share on other sites More sharing options...
Bowmore Posted February 19, 2011 Share Posted February 19, 2011 I'm sure that this process would be a lot simpler if you ditched the bat files and made the whole process a single autoit script. However try this. I think it does what you asked for. #include <file.au3> #include <array.au3> msgbox(0,"","starting cut") dim $array _FileReadToArray(@scriptdir & "\list.txt",$array) ;find the line # of the cut. the line # where the cut is is stored in $line ;$array[0] is the total lines of the file. For $i = 1 to $array[0] Step 1 $pos = StringInStr($array[$i],"Cuthere") $line = $i if $pos <> 0 then cuthere() Next Func cuthere() $file = FileOpen(@scriptdir & "\list.txt") $xline = FileReadLine($file,$line) ; ;$xline is the entire cut string. used to locate the rest of the file. ; $dump = fileopen("result.txt",10) $teext = fileread($file) FileWrite($dump, $teext) ;msgbox(0,"",$teext) fileclose($file) fileclose($dump) ;$file = FileOpen(@scriptdir & "\list.txt", 2) ;fileclose($file) $R = processclose("cmd.exe") ;~ MsgBox(262144,'Debug line ~' & @ScriptLineNumber,'Selection:' & @lf & '$R' & @lf & @lf & 'Return:' & @lf & $R) ;### Debug MSGBOX ProcessWaitClose("cmd.exe") EndFunc "Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the universe trying to build bigger and better idiots. So far, the universe is winning."- Rick Cook Link to comment Share on other sites More sharing options...
PowerCat Posted February 19, 2011 Author Share Posted February 19, 2011 I'm sure that this process would be a lot simpler if you ditched the bat files and made the whole process a single autoit script.However try this. I think it does what you asked for.Thanks for your answer Bowmore, but this also stops the rest of the loop from running correctly.Only cut_pkg_list may change, and it has to stop the FOR loop called by list.bat, while succesfully running the second loop. Link to comment Share on other sites More sharing options...
Bowmore Posted February 19, 2011 Share Posted February 19, 2011 One last attempt . #include <file.au3> #include <array.au3> msgbox(0,"","starting cut") dim $array _FileReadToArray(@scriptdir & "\list.txt",$array) ;find the line # of the cut. the line # where the cut is is stored in $line ;$array[0] is the total lines of the file. FileDelete(@scriptdir & "\list.txt") $file = FileOpen(@scriptdir & "\listDone.txt",2) For $i = 1 to $array[0] Step 1 If StringInStr($array[$i],"Cuthere") Then $i += 1 FileClose($file) $file = FileOpen(@scriptdir & "\result.txt",10) EndIf FileWriteLine($file,$array[$i]) Next FileClose($file) processclose("cmd.exe") ProcessWaitClose("cmd.exe") RunWait(@ComSpec & ' /c "' & @ScriptDir & '\list.bat"') FileMove(@scriptdir & "\listDone.txt",@scriptdir & "\list.txt",1) "Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the universe trying to build bigger and better idiots. So far, the universe is winning."- Rick Cook Link to comment Share on other sites More sharing options...
PowerCat Posted February 19, 2011 Author Share Posted February 19, 2011 This new technique is quite interesting, but the problem is using ProcessClose for this purpose breaks out of the entire batch file, this is where the challenge lies. We have to cleanly exit the loop created by the FOR command in the batch file. Link to comment Share on other sites More sharing options...
Bowmore Posted February 19, 2011 Share Posted February 19, 2011 If we are only allowed to change cut_pkg_list.au3, then i think that cleanly breaking out of the loop in list.bat as you request is impossible. "Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the universe trying to build bigger and better idiots. So far, the universe is winning."- Rick Cook Link to comment Share on other sites More sharing options...
PowerCat Posted February 19, 2011 Author Share Posted February 19, 2011 If we are only allowed to change cut_pkg_list.au3, then i think that cleanly breaking out of the loop in list.bat as you request is impossible.I think you are right. This might not be possible to do. Link to comment Share on other sites More sharing options...
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