Sign in to follow this  
Followers 0
Woot

controlsend sending incorrect characters to putty

2 posts in this topic

I've made a few scripts that use putty for logging into various unix based machines. I've been facing one issue throughout: occasionally some characters of any text string thats being sent to putty are replaced by characters that werent in the original text string. Heres some code to explain what i mean, assume ive already run putty.exe:

$putty=WinList($pname) ;$putty[1][1] will contain newest putty window handle

ControlSend("","",$putty[1][1],"physap_rfh_list_devices" & "{ENTER}")

Most of the time this sends the text string correctly but sometimes you'd get something like physap-rfh-list_devices (- instead of _). This is just one example. I've made over 2 dozen scripts involving putty and all of them show this behaviour at seemingly random points. I suspect that sending characters which involve holding down shift have something to do with it, since so far these are the only ones I've noticed as being sent incorrectly (i could be wrong). To get around this issue i tried replacing controlsend with a function that i made (called uber_send) which first converts any text string into ascii values and then send those values. This didnt help either, though heres the code for the function i used:

Func uber_send($a,$b,$c,$d)

Dim $enter=0

If StringInStr($d,"{ENTER}")=True Then

$enter=1

$d=StringReplace($d,"{ENTER}","")

EndIf

$ascii=StringToASCIIArray($d)

$end=UBound($ascii)-1

For $x=0 To $end Step +1

ControlSend($a,$b,$c,"{ASC"&" "&$ascii[$x]&"}")

Next

If $enter=1 Then

ControlSend($a,$b,$c,"{ENTER}")

EndIf

EndFunc

I've been working on automizing putty for quite some time and I've got everything else down perfect. I can keep track of different putty windows and check their outputs using log files. But I just cant seem to get around this particular problem. So far I've avoided posting on forums since whenever I've been stuck on something I've found the solution on older posts but im kind of desperate now. I promised my manager that I'd deliver a single executable which will basically be a sort of a single management GUI for all the scripts I've developed over the past year. These number close to 25 and all of them involve putty. If I dont troubleshoot this, none of them can be considered reliable enough. Its not practically feasible to do error checking after every Controlsend (or uber_send) since my code is over 4000 lines and I'd have a metal breakdown going through all that again. Any idea if this is an issue with putty or autoit or just my laptop/OS. I've noticed when I have the autoit info tool open, more characters are sent incorrectly.

Any suggestions would be appreciated. im supposed to float this nationwide throughout the organization by friday so my ass is pretty much on the line.

Share this post


Link to post
Share on other sites



btw uber_send has the same 4 argumentes/parameters as controlsend. i did this so I could interchange the 2 with find and replace all option.

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