Jump to content

Breaking out of the DOS FOR loop which called the AutoIT Script


PowerCat
 Share

Recommended Posts

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

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

Please halp! This is quite puzzling.

I hope I’m expressing myself correctly. English is not my mother tongue.

Edited by PowerCat
Link to comment
Share on other sites

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 parsingAutoIt SearchAutoIt3 PortableAutoIt3WrapperToPragmaAutoItWinGetTitle()/AutoItWinSetTitle()CodingDirToHTML5FileInstallrFileReadLastChars()GeoIP databaseGUI - Only Close ButtonGUI ExamplesGUICtrlDeleteImage()GUICtrlGetBkColor()GUICtrlGetStyle()GUIEventsGUIGetBkColor()Int_Parse() & Int_TryParse()IsISBN()LockFile()Mapping CtrlIDsOOP in AutoItParseHeadersToSciTE()PasswordValidPasteBinPosts Per DayPreExpandProtect GlobalsQueue()Resource UpdateResourcesExSciTE JumpSettings INISHELLHOOKShunting-YardSignature CreatorStack()Stopwatch()StringAddLF()/StringStripLF()StringEOLToCRLF()VSCROLLWM_COPYDATAMore Examples...

Updated: 22/04/2018

Link to comment
Share on other sites

The loop is not from autoit.

But this is an AutoIt Forum! Edited 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 parsingAutoIt SearchAutoIt3 PortableAutoIt3WrapperToPragmaAutoItWinGetTitle()/AutoItWinSetTitle()CodingDirToHTML5FileInstallrFileReadLastChars()GeoIP databaseGUI - Only Close ButtonGUI ExamplesGUICtrlDeleteImage()GUICtrlGetBkColor()GUICtrlGetStyle()GUIEventsGUIGetBkColor()Int_Parse() & Int_TryParse()IsISBN()LockFile()Mapping CtrlIDsOOP in AutoItParseHeadersToSciTE()PasswordValidPasteBinPosts Per DayPreExpandProtect GlobalsQueue()Resource UpdateResourcesExSciTE JumpSettings INISHELLHOOKShunting-YardSignature CreatorStack()Stopwatch()StringAddLF()/StringStripLF()StringEOLToCRLF()VSCROLLWM_COPYDATAMore Examples...

Updated: 22/04/2018

Link to comment
Share on other sites

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

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

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

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

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

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