Jump to content

Replacing DOS "FOR" command


Recommended Posts

I have a dos batch file I would like to integrate in with other autoit functions, but not sure how to replace. Here is what the DOS batch does:

for /f "skip=2 tokens=1-4 delims=," %%a in ('find /i "%ClientName%" "%Client-TTYIDFileLocation%\%Client-TTYIDFileName%"') do if not [%%b]==[] (

if [%%c]==[] goto ERR

if [%%d]==[] goto ERR

call :Normal %%b %%c %%d

goto end )

:Normal

call %haPath%\%haEXE% /TTYID=%1 /HOST=%CAFHost% /PORT=%CAFPort%

goto end

Basically there is a file that has a list of clientnames so it searches for a match and grabs the TTY,Host, and port from that file that matches for that client id and uses those values as parameters to start a program.

Any ideas?

Link to comment
Share on other sites

Looked like fun, so I took a stab at it:

#include <File.au3>

Opt("ExpandEnvStrings", 1)

Global $sClientName = "%ClientName%"
Global $sFile = "%Client-TTYIDFileLocation%\%Client-TTYIDFileName%"
Global $aFile[1], $aSplit[1]

_FileReadToArray($sFile, $aFile)
For $n = 1 To $aFile[0]
    $aSplit = StringSplit($aFile[$n], ",")
    If $aSplit[0] >= 6 Then
        If $aSplit[4] <> "" Then
            If ($aSplit[5] <> "") And ($aSplit[6] <> "") Then
                _Normal($aSplit[4], $aSplit[5], $aSplit[6])
            Else
                _Error()
            EndIf
        EndIf
    EndIf
Next

Func _Normal($sB, $sC, $sD)
    #forceref $sC, $sD
    Run("%haPath%\%haEXE% /TTYID=" & $sB & " /HOST=%CAFHost% /PORT=%CAFPort%")
EndFunc   ;==>_Normal

Func _Error()
    MsgBox(16, "Error", "Error")
    Exit
EndFunc   ;==>_Error

There are some extra variables with no use here, but it reflects the posted batch script.

:mellow:

Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law
Link to comment
Share on other sites

Thanks, I will give it a shot -looks promising!

Looked like fun, so I took a stab at it:

#include <File.au3>

Opt("ExpandEnvStrings", 1)

Global $sClientName = "%ClientName%"
Global $sFile = "%Client-TTYIDFileLocation%\%Client-TTYIDFileName%"
Global $aFile[1], $aSplit[1]

_FileReadToArray($sFile, $aFile)
For $n = 1 To $aFile[0]
    $aSplit = StringSplit($aFile[$n], ",")
    If $aSplit[0] >= 6 Then
        If $aSplit[4] <> "" Then
            If ($aSplit[5] <> "") And ($aSplit[6] <> "") Then
                _Normal($aSplit[4], $aSplit[5], $aSplit[6])
            Else
                _Error()
            EndIf
        EndIf
    EndIf
Next

Func _Normal($sB, $sC, $sD)
    #forceref $sC, $sD
    Run("%haPath%\%haEXE% /TTYID=" & $sB & " /HOST=%CAFHost% /PORT=%CAFPort%")
EndFunc   ;==>_Normal

Func _Error()
    MsgBox(16, "Error", "Error")
    Exit
EndFunc   ;==>_Error

There are some extra variables with no use here, but it reflects the posted batch script.

:mellow:

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