Jump to content
Sign in to follow this  
AutoITPimp

Reading from PuTTy or DOS prompt

Recommended Posts

AutoITPimp

I've been using AutoIT for a while now and find it quite useful. I taught myself how to program with it, however, one obstacle I have not been able to overcome is how to get text from command promps. More specifically from a program called PuTTy.

I am developing an automated device checking tool for my company, and it involves opening PuTTy to run an SSH connection to various *nix servers to check and see if the device is in use or not from a BASH prompt. The AutoIT Window Info tool does not detect the command screen, so I'm not sure how to capture the reply messages I am receiving. I've tried someing like this, but it doesn't work. Any suggestions?

This is what I tried, and then had to change to a msgbox for the user to check and deccide whether to continue or not.

;$winText = WinGetText ( "***.***.***.*** - PuTTY", "" )
;If StringInStr ( "$winText", "No rows selected.", 0, 1 ) <> 0 then
    ;Insert()
;EndIf

 $reply = MsgBox( 4, "Proceed?", "Proceed with insert?" )
   if $reply = 6 then 
     Insert()
   EndIf
Edited by AutoITPimp

Share this post


Link to post
Share on other sites
layer

The only thing I can help you with, is this:

;If StringInStr ( "$winText", "No rows selected.", 0, 1 ) <> 0 then

Should be:

;If StringInStr ( $winText, "No rows selected.", 0, 1 ) <> 0 then

Noticed I removed the """ around the variable $winText... Even though it's a comment, it should still be right :dance: But I don't think this will get you far, someone else can probably help. :whistle:

Edited by layer

FootbaG

Share this post


Link to post
Share on other sites
AutoITPimp

Actually, that was just a typo in my post. I tried it this time on another script and it seems to work. I think my problem is that I was actually trying to use ControlGetText function. =P

But, is there a better way to read this, or to know when a reply comes back from the server?

**EDIT: After some checking and playing with the function it appears it does not work. The AutoIT Window Info tool does not show any window text for command prompts or PuTTy, and when MsgBox for the text received from WinGetText, it displays an empty MsgBox. As I recall, this is the problem I have had in the past.

Edited by AutoITPimp

Share this post


Link to post
Share on other sites
DaveF

The AutoIt beta had functions for reading output and writing input directly from console apps, rather than scraping the text from a window: StdoutRead, StdinWrite, etc.

I've used Plink, one of the PuTTY tools, to run a SSH session using the functions above, but it's not pretty; there's no terminal per se so you get ANSI control characters and junk in the strings that you read.


Yes yes yes, there it was. Youth must go, ah yes. But youth is only being in a way like it might be an animal. No, it is not just being an animal so much as being like one of these malenky toys you viddy being sold in the streets, like little chellovecks made out of tin and with a spring inside and then a winding handle on the outside and you wind it up grrr grrr grrr and off it itties, like walking, O my brothers. But it itties in a straight line and bangs straight into things bang bang and it cannot help what it is doing. Being young is like being like one of these malenky machines.

Share this post


Link to post
Share on other sites
commenti

Hello AutoITPimp,

I´am not sure if this helps in your situation but I wrote once a script to retreive my current public IP by logging into my router via telnet. I was able to send something to the command prompt but not getting text from it, so I redirected the output to a file and parsed that. Here is what I wrote (quite old, one of my first autoIt scripts).

AutoItSetOption("WinDetectHiddenText", 1)


; ----------------------------------------------------------------------------
; Script Start
; ----------------------------------------------------------------------------

Run ( "telnet 192.168.0.1 -f " &@TempDir & "\routerip.log" , "e:", @SW_HIDE )
WinWait("Telnet 192.168.0.1")
ControlSend ( "Telnet 192.168.0.1", "", "", "password")
ControlSend ( "Telnet 192.168.0.1", "", "", "show ip{ENTER}")
$var = ControlGetText("Telnet 192.168.0.1", "", "ConsoleWindowClass")
ControlSend ( "Telnet 192.168.0.1", "", "", "log{ENTER}{ENTER}")
$file = FileOpen(@TempDir & "\routerip.log", 0)
If $file = -1 Then
    MsgBox(0, "Error", "Unable to open file.")
    Exit
EndIf

While 1
   $line = FileReadLine($file)
   If @error = -1 Then ExitLoop
   IF (StringInStr ( $line, "ewanisp")) Then
      $line = StringMid ( $line, 33, 15 )
      MsgBox(0, "Aktuelle IP", $line)
   EndIf
Wend
 
FileClose($file)

FileDelete (@TempDir & "\routerip.log")

Don´t know if this is of any use.

commenti

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  

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.