Jump to content

Terminal Emulation using StdOut


Derp
 Share

Recommended Posts

Hi,

I've read lots of topics on this and I'm not having any luck sorting out my issue, the code I've used (posted below) is a sample from one of the posts in this forum, which is kind of working for me.

I'm trying to write a script to behave like a VT100. In the past I've done what I need to do via an application, such as TTWin, or Teraterm, what I want to do is use is 'console telnet' (http://consoletelnet.sourceforge.net/) and STDIN/OUT, however, I am encountering some issues with the responses from the server.

I have a feeling the problem has something to do with the configuration, but where I am confused, is that when I "Manually" connect just by running the 'console telnet' software, everything shows up and looks perfect (formatting is there, the text is actually there). Here is what happens when I try to use autoit:

----------------------------------------------------------------------------------------------------

[H[2J[m

#6[1mUnauthorized Access Prohibited[m

Username: REMOVED

Password:

Last interactive login on Friday, 5-AUG-2011 13:45

[c\Z[0c

%SET-W-NOTSET, error modifying TNA7221:

-SET-I-UNKTERM, unknown terminal type

[c\Z[0c

%SET-W-NOTSET, error modifying TNA7221:

-SET-I-UNKTERM, unknown terminal type

Terminal type is not TDMS compatible, continuing without TDMS support

No layout in the DECforms form for menu fits this terminal type, language, and d

isplay size

Selection:

----------------------------------------------------------------------------------------------------

Here is what should show after that screen:

----------------------------------

Information System Main Menu

1 TRAC M Tracking System

2 CIS M Information System

3 CUST_INQ T Customer Inquiry

4 ACCT_RECV M Accounts Receivable System

5 NMS M Management System

6 IMS M Inventory System

7 UTILITIES M Utilities System

Selection:

----------------------------

EnvSet("TELNET_REDIR", "1")

Dim $PID = Run("C:\Documents and Settings\asdasdasdasd\Desktop\AutoIT\scripts\run while locked\ConsoleTelnet\telnet.exe", @SystemDir, @SW_HIDE, $STDIN_CHILD + $STDOUT_CHILD)
Dim $Triggers[50]
Dim $Actions[50]

AdlibRegister("CheckTriggers", 500)

_Connect($PID, "asdasd-ol1", 23, 3000)
_Login($PID, "asdsad", "asdasdad", 500) ; Logs in.

$Triggers[0] = 1 ; Number of Triggers
$Triggers[1] = "C:\Documents and Settings\" 

$Actions[0] = 0
$Actions[1] = "dir" ; This happens if $Trigger[1] is detected.

While 1
    Sleep(500)
WEnd

Func CheckTriggers()
    local $Line
    $Line = StdoutRead($PID)
    ConsoleWrite($Line)
    For $N = 1 To $Triggers[0]
        If StringInStr($Line, $Triggers[$N]) Then
            StdinWrite($PID, $Actions[$N] & @CRLF)
        EndIf
    Next
EndFunc

Func _Connect($STD_Handle, $Server, $Port, $Sleep)
    StdinWrite($STD_Handle, "open " & $Server & " " & $Port & @CRLF)
    While 1
        $Line = StdoutRead($STD_Handle)
        If StringInStr($Line, "Connected to") Then
            Sleep($Sleep)
            Return 1
        EndIf
        If StringInStr($Line, "Error") Then
            Return 0
        EndIf
    WEnd
EndFunc

Func _LogIn($STD_Handle, $Username, $Password, $Sleep)
    StdinWrite($STD_Handle, $Username & @CRLF)
    Sleep($Sleep)
    StdinWrite($STD_Handle, $Password & @CRLF)
EndFunc


Func Close()
    AdlibUnRegister("CheckTriggers")
    ProcessClose("telnet.exe")
    Exit
EndFunc
Link to comment
Share on other sites

Never mind, I resolved this myself.

Even though the text shows up garbled and misformated it seems to work, I waited a few seconds and told the server that I was a VT100 with the following command:

StdinWrite($STD_Handle, chr(27) & "[?1;0c" & @CRLF)

Link to comment
Share on other sites

  • 3 months later...

Hello!

When using your script, you get a message login failed, but if you enter it manually in telnet.exe, that's all right. In what may be the problem?

upd:

put a little more delay, everything works.

Edited by Deito
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...