piratao2 Posted May 12, 2009 Share Posted May 12, 2009 (edited) I'm working on an autoit program that should run some PuTTY sessions to remote servers. The problem that I'm having is that I cannot ensure the session has been already opened or not. And I need to know that before I send commands to that window. I managed to detect the time when the prompt appears by reading stdout and then stopping the while loop once a char that is present on the prompt is detected: $handle = Run($strCmd, @ScriptDir, @SW_MAXIMIZE, $STDIN_CHILD + $STDOUT_CHILD) $line="" While not StringInStr($line,">") $line &= StdoutRead($handle) If @error Then ExitLoop Wend MsgBox(0, "STDOUT read:", $line) This works fine to detect the prompt, and hence I could start to send commands to the terminal. But I don't seem to be able to return the default output back to the terminal window. Is it possible? The output should occur on the terminal window because I'm automating just the initial and repetitive tasks that we need to do on the servers once we logon. Once those initial commands are executed, we need to enter other commands manually according to each situation, so it's impossible to automate this part. Another question, if the above is not possible, can I find a specific window by PID? The $handle variable returns the PID, then I could at least wait until the right specific window is there and setup some sleep between each command that I will send to the terminal window. For those who would suggest to use the window name to find the specific window, I've already tried it and it's not working well because I usually have many terminal windows opened. Thanks in advance. Edited May 12, 2009 by piratao2 Link to comment Share on other sites More sharing options...
piratao2 Posted May 12, 2009 Author Share Posted May 12, 2009 Going forward with the research, I don't see any function on the help file that I could use to recover the stdout back to the terminal window. Maybe it is not possible... Maybe there is a dll call that somebody knows? Link to comment Share on other sites More sharing options...
ResNullius Posted May 12, 2009 Share Posted May 12, 2009 Another question, if the above is not possible, can I find a specific window by PID?http://www.autoitscript.com/forum/index.php?showtopic=37289Question 25- I have run a program, but how can I get the window handle? Link to comment Share on other sites More sharing options...
piratao2 Posted May 12, 2009 Author Share Posted May 12, 2009 ResNullius, thanks, I'm implementing that function right now on my code. That would be a way to activate and perhaps send the commands only to the right window. I'm also implementing the code needed to read the PuTTY log file, and to detect when a trigger character (or text) appears on the log. This way the script will know the logon has occured... Still wanted to be able to grab the text directly from PuTTY window. Thanks! Link to comment Share on other sites More sharing options...
ResNullius Posted May 12, 2009 Share Posted May 12, 2009 Still wanted to be able to grab the text directly from PuTTY window.What about Valik's work with screen scraping by attaching to the console of the process? Needs XP as a minimum OS I think.http://www.autoitscript.com/forum/index.ph...st&p=527810 Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now