Jump to content

The first script problem


APRES
 Share

Recommended Posts

The first script I made ( HelloWorld )

should do the following

Run ( "C:\putty.exe -load AT" )
WinActivate("192.168.10.1 - PuTTY" )
WinWaitActive ( "192.168.10.1 - PuTTY" )
Sleep(10000) ;pause 10 seconds
WinActivate("192.168.10.1 - PuTTY" )
Send ( "login{ENTER}" )
Sleep(10000) ;pause 5 seconds
WinActivate("192.168.10.1 - PuTTY" )

Then few times

Send ( "some keystroke")
Sleep(2000)
WinActivate("192.168.10.1 - PuTTY" )

All of it I compiled and scheduled as wintask to execute nightly.

It works well. :dance:

But not always. :whistle:

Sometimes I come next day and see that it remains on login screen. It looks like some process running on computer takes it over. Therefore I used

WinActivate for every step. But it doesn't help either.

What am I doing wrong?

Link to comment
Share on other sites

  • Developers

try a WinWait() between the first 2 statements, because you need to pause to give Putty time to launch before activating...

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Link to comment
Share on other sites

  • Developers

Also adding of WinWait()  didn't help.

Today again program stopped at log in.

Is there any way to go further? (to debug it somehow)

<{POST_SNAPBACK}>

Add Opt("TrayIconDebug", 1) to your script to deterime where it is stopping.....

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Link to comment
Share on other sites

Also adding of WinWait()  didn't help.

Today again program stopped at log in.

Is there any way to go further? (to debug it somehow)

<{POST_SNAPBACK}>

I find that the length of time required to get the "login as:" prompt in PuTTY can vary tremendously. Assuming that the first string you are sending is the username you may need to put a substantial Sleep in the code before you send it.

Also, you can avoid the potential problem of another window taking focus by using ControlSend instead of Send (a ControlID is not actually required). Here is what works for me:

Run ( "C:\putty.exe -load your-config" )
$title = "your-IP - PuTTY"
WinWait($title )
$handle = WinGetHandle($title)
Sleep(15000); sleep 15 seconds - just keep shorter than the login timeout
ControlSend ( $handle, "", "", "username{ENTER}" )
ControlSend ( $handle, "", "", "password{ENTER}" )

Edit: Just realized that since the window title won't change, there should be no need for the complexity of using the handle. This will work just as well:

Run ( "C:\putty.exe -load your-config" )
$title = "your-IP - PuTTY"
WinWait($title )
Sleep(15000); sleep 15 seconds - just keep shorter than the login timeout
ControlSend ( $title, "", "", "username{ENTER}" )
ControlSend ( $title, "", "", "password{ENTER}" )

Dale

Edited by DaleHohm

Free Internet Tools: DebugBar, AutoIt IE Builder, HTTP UDF, MODIV2, IE Developer Toolbar, IEDocMon, Fiddler, HTML Validator, WGet, curl

MSDN docs: InternetExplorer Object, Document Object, Overviews and Tutorials, DHTML Objects, DHTML Events, WinHttpRequest, XmlHttpRequest, Cross-Frame Scripting, Office object model

Automate input type=file (Related)

Alternative to _IECreateEmbedded? better: _IECreatePseudoEmbedded  Better Better?

IE.au3 issues with Vista - Workarounds

SciTe Debug mode - it's magic: #AutoIt3Wrapper_run_debug_mode=Y

Doesn't work needs to be ripped out of the troubleshooting lexicon. It means that what you tried did not produce the results you expected. It begs the questions 1) what did you try?, 2) what did you expect? and 3) what happened instead?

Reproducer: a small (the smallest?) piece of stand-alone code that demonstrates your trouble

Link to comment
Share on other sites

Thank you.

Almost sure that just the difference between

Send and ControlSend

will makes a trick. "ControlSend" would act also if a control lost focus and "Send" won't , isnt'it?

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