Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

Is there a way to retrieve the contents of the Putty buffer from an AutoHotKey script? For many applications, WinGetText works, but it doesn't seem to for Putty. Also, the AHK Windows Spy doesn't display any text from the buffer, so I suspect that Putty simply uses a different method of storage/display for it's buffer.

I'm wondering if either you can enable a setting in Putty such that it will expose the contents of it's buffer in a Window-standard way that AHK could then pick up as the Visible Window Text.

Alternatively, I suppose there may be some feature of AHK that I'm not aware of that can get that text, but that seems less likely.

share|improve this question
1  
What are you trying to do overall? –  bobmagoo Aug 21 '12 at 0:12
    
Attachmate Reflections macros can be set up to wait until it sees certain text in the screen before it does a "Send". So if I want to have AHK automatically enter my username at a prompt, I can have the AHK script wait until the "Username:" prompt displays (for, say, a db login). I'm currently using AHK "Send", in combination with sleep,100 to handle the case where a database login prompt is slow to load (I have a db login script set to run from .profile at login). –  Cooper Aug 24 '12 at 20:51
    
I mean, overall, what are you trying to accomplish? Automatically connect to a database? Send something? –  bobmagoo Aug 25 '12 at 13:05
    
Yes - I want to automatically connect (and login) to a database. This involves navigating a series of text menus as well. –  Cooper Sep 6 '12 at 15:37
    
What database are you connecting to? From what? Surely there's an easier way to connect to a database than screen scraping. –  bobmagoo Sep 6 '12 at 16:11

2 Answers 2

I've done this sort of process before using the ImageSearch command: take a screenshot of an empty login prompt, and use ImageSearch to determine if the prompt has been reached. I've found this to be relatively reliable (though by no means perfect) - it may work for you!

For a more reliable system you'd probably need to write a script which does the ssh interaction for you, for example python with pexpect, which I have used successfully. Instructions on how to do that are outside the scope of this question, but depending on what scripting languages you are familiar (other than AutoHotKey) I'm sure there would be an option. I've no experience doing this kind of thing in perl, but it may be possible.

share|improve this answer

I read a different approach: Have PuTTY write contents to a log file. Then have AutoHotKey read from a file. This may provide the relevant info:

autoputty-scripted-telnet-need-help

Here's another approach:

gist.github.com/serf/2710415

It involves selecting text, which copies it to the clipboard, and then have AutoHotKey read from the clipboard. (It also saves a copy of the clipboard before clobbering the clipboard, and restores the backed up clipboard data).

buixuanlinh.com/blog/?p=80

shows a simple example of logging in with PuTTY.

AutoHotkey:_Launch_putty_or_RDP_sessions_via_a_tree-driven_selection_menu

I've tested zero of these solutions. So, good luck.

If you have access to the server, you may wish to look into doing stuff on the server side. For instance, you can have an SSH key that only permits the user to run one command (or the start of a command, like "sudo mount" but not "sudo anything-else"); sudo can also provide restrictions on what command is used. OpenSSH can allow a single user to have multiple keys. So, choosing which key you use, on the local/client end, could affect that happens when you connect to the server. Details, which will probably be useful for anyone wishing to explore this route, may be found from:

cyberpillar.com/dirsver/1/mainsite/techns/netfeats/users/usrbasop/userauth/authkeyf/authkeyf.htm#sshkycmd

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.