Sign in to follow this  
Followers 0
lsakizada

Help to manage telnet application

1 post in this topic

#1 ·  Posted (edited)

Hi, I am trying to developed tool that utilized telnet application to send unix commands inside autoit application.

The application read commands from files and send them to the telnet application. see bellow.

The application read and write to the telnet via the stdInread and stdoutwrite functions.

The first commands (login and password ) that sent to the via the telnet are working, but once the user logged in, the commands are not working somehow. I am unable to figure out what is wrong.

The simple unix commands should be placed in a text file called conf.txt in the current running directory.

login:=user         
Password:=password
>=cd ~
>=pwd

#include <GuiConstants.au3>
#Include <File.au3>
EnvSet("TELNET_REDIR", "1")

Global $UserName = "username", $PassWord = "password", $IPAddress = "ipaddress"

Global $ourProcess ,  $x
Dim $aRecords

GuiCreate("Telnet: Celltick Automation", 425, 322,(@DesktopWidth-425)/2, (@DesktopHeight-362)/2 , $WS_OVERLAPPEDWINDOW + $WS_VISIBLE + $WS_CLIPSIBLINGS)
$eOutput = GuiCtrlCreateEdit("", 0, 10, 423, 260, BitOR($ES_WANTRETURN, $WS_VSCROLL, $WS_HSCROLL, $ES_AUTOVSCROLL, $ES_AUTOHSCROLL, $ES_READONLY))
$bExit = GuiCtrlCreateButton("Exit", 340, 285, 60, 20)
$ourProcess = Run(@ProgramFilesDir & "\telnet\telnet.exe "&$IPAddress, @ProgramFilesDir & "\telnet", @SW_HIDE,  3)
GuiSetState()

If Not _FileReadToArray("conf.txt",$aRecords) Then
   MsgBox(4096,"Error", " Error reading file to Array error:" & @error)
   Exit
EndIf

Global $Array[$aRecords[0]]

$x=1
While 1
    If $ourProcess Then
        $charsWaiting = StdoutRead($ourProcess, 0 , 1)
        If @error = -1 Then
             $ourProcess = 0
                MsgBox(0, "App Exited", "Process has exited...")
             ContinueLoop
        EndIf
        If $charsWaiting > 0 Then
            $currentRead = StdoutRead($ourProcess)
            GUICtrlSetData($eOutput, $currentRead, 1)
            $splited =StringSplit ( $aRecords[$x], "=")
            If StringInStr($currentRead, $splited[1]) <> 0   Then
                StdinWrite($ourProcess, $splited[2] &  @CRLF)
                $x = $x +1  
            EndIf
        EndIf
    EndIf
Edited by lsakizada

Be Green Now or Never (BGNN)!

Share this post


Link to post
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
Sign in to follow this  
Followers 0