JohnReilly54 Posted October 23, 2014 Share Posted October 23, 2014 I have a lot of experience with VB6 and VBA (including a lot of Windows API calls). I wrote a large Autoit script about 4 years ago to simulate a Telnet session. There is an INI file that I read a sequence of instructions from and wait for a command line response (configurable for each command, if required). It has been working unchanged since I wrote it originally, using many different configurations in the INI file. However recently we have discovered an issue with the use of the "_" character being altered (intermittently) to the "-". I have added logging to the code to allow me to see if the command is becoming corrupted and it is fine before being used by the ControlSend function. The overall programme starts a cmd window redirecting the standard output to a file. Thus this file contains the commands being sent into the device connected via telnet and also the responses which always show the invalid command. Thus I might have a command to send such as "get info 1 pwr_supply_temp" and what is sent by the telnet window is "get info 1 pwr-supply-temp". Command that do not have underscore characters ALWAYS work fine, but fail on these commands. We have not been able to find a pattern to when the issue starts but it will continue until we check the results (the result file size will be smaller because requested data is not returned). Sometimes checking the results will "fix" it and others it will not. The script is set up to send these commands by running the Autoit script on an hourly basis on the machine by the scheduler (which has no keyboard or display), which we RDP into to check. However we have tried it on 4 different machines some with keyboards displays, and permanently logged in and still the same issue. expandcollapse popup;$TelnetHWND is a global variable ;************Test Logging If StringInStr($sendtxt, "_", 2, 1) Or StringInStr($sendtxt, "-", 2, 1) Then Write2Log("About to Send Command '" & $sendtxt & "'") EndIf ;---------------------------------- ; Code that I have issue with ;----------------------------------- ; Send the Text ControlSend($TelnetHWND, "", "", $sendtxt & "{ENTER}") ; ; ; ; ; ; Code fragment from elsewhere used to start Telnet window.... $Result = StartTelnet($IP, $IPFileName) ; First Check for an error If @error = 0 Then ; And have we returned a Handle If IsHWnd($Result) = True Then $TelnetHWND = $Result $bContinue = True Else $bContinue = False EndIf EndIf ; ; Routine to Start Telnet Func StartTelnet($IP, $Dest_IPFileName) ; ; $Telnet = Run(@WindowsDir & "\system32\telnet.exe " & $IP & " -f " & Chr(34) & $Dest_IPFileName & Chr(34), "", $show_flag) ; ; Now wait for the window to be Open..; WinWaitActive("Telnet", "", 10) ; Local $hWnd = _GetHwndFromPID($Telnet) Return $hWnd EndFunc ;==>StartTelnet ; ; Logging These 2 routines used to create file name & write to log Func LogFileName() $Day = "0" & @MDAY Return @YEAR & @MON & $Day & ".log" EndFunc ;==>_LogFileName ; Func Write2Log($Text) $file = FileOpen(LogFileName(), 1) ; Check if file opened for writing OK If $file = -1 Then ;MsgBox(0, "Error", "Unable to open file.") Exit EndIf FileWriteLine($file, _Now() & " - " & $Text & @CRLF) FileClose($file) EndFunc ;==>_Write2Log The Overall script is almost 1,000 lines long and there is a lot of proprietary stuff inside the code (how connections are made under different circumstances). It is used on a proprietary system which has NO connections to the internet and everything is protected by multiple firewalls etc. Anyway it runs on Windows XP (V5.1 SP2, build 2600) and this is causing many commands to fail. Link to comment Share on other sites More sharing options...
Zedna Posted October 23, 2014 Share Posted October 23, 2014 Look here Resources UDF ResourcesEx UDF AutoIt Forum Search Link to comment Share on other sites More sharing options...
Zedna Posted October 23, 2014 Share Posted October 23, 2014 Instead of ControlSend() you can do Telnet session by using TCP Send/Receive functions like in this example http://www.autoitscript.com/forum/index.php?s=&showtopic=21498&view=findpost&p=150751 Search forum for Telnet (in titiles only) for more information and examples how to avoid using ControlSend() with Telnet ... Resources UDF ResourcesEx UDF AutoIt Forum Search 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