monte Posted February 25, 2006 Share Posted February 25, 2006 Hello, I'm having trouble getting text from a window. It keeps returning 1 which is a windows title error. Even though I've tried wingettitle and it returns 1! Please help. expandcollapse popup#include <GUIConstants.au3> #include <array.au3> #notrayicon $checkRun = "Emc Script" If WinExists($checkRun) Then Exit GUICreate("Emc Script", 350, 260) GUISetBkColor (0xA9A9A9) Global $defaultstatus = "Ready" Global $status $filemenu = GUICtrlCreateMenu ("&File") $filehotkeyitem = GUICtrlCreateMenuitem ("Hot Keys",$filemenu) $fileexititem = GUICtrlCreateMenuitem ("Exit",$filemenu) $helpmenu = GUICtrlCreateMenu ("&Help") $helpreadmeitem = GUICtrlCreatemenuitem ("Readme",$helpmenu) $separator1 = GUICtrlCreateMenuitem ("",$filemenu,2); create a separator line GUICtrlSetState(-1,$GUI_FOCUS) $statuslabel = GUICtrlCreateLabel ($defaultstatus,0,220,350,16,BitOr($SS_SIMPLE,$SS_SUNKEN)) $button1 = GUICtrlCreateIcon ("C:\program files\routericon.bmp", 0, 140,80) GUISetState () While 1 $msg = GUIGetMsg() If $msg = $GUI_EVENT_CLOSE Or $msg = $fileexititem Then ExitLoop If $msg = $helpreadmeitem Then run(@ComSpec & " /c C:\\damewa~1\damewa~1\dntu.exe", "", @SW_HIDE) Select Case $msg = $button1 router() EndSelect WEnd func router() dim $routertext =1 while $routertext =1 $user= inputbox("Authentication", "Please enter your tacacs username","", " M") $pass= inputbox("Authentication", "Please enter your tacacs password", "", "*M") $mycmd=" /c telnet " $aMy[1]= @ComSpec $aMy[2]= $mycmd $aMy[3]= $vServer $aMy[4]= "" $aMy[5]= @SW_SHOW $hwin= Run($aMy[1] & $aMy[2] & $aMy[3], $aMy[4], $aMy[5]) sleep(1000) winactivate("telnet") send($user) send("{ENTER}") sleep(500) send($pass) send("{ENTER}") sleep(1000) $text = WinGetText("") sleep(500) msgbox(1,"",$text) $mystr1=stringinstr($text,">",0,1) if $mystr1 = 1 then send("sh ver") send("{ENTER}") send("{SPACE 10}") sleep(1000) send("{ENTER 3}") send("sh log | in " & $int & $intNum) send("{ENTER}") send("{SPACE 10}") sleep(1000) send("{ENTER 3}") send("sh int " & $intTmp) send("{ENTER}") send("{SPACE 10}") sleep(1000) send("{ENTER 3}") send("sh ip int brie | in " & $int & $intNum) send("{ENTER}") send("{SPACE 10}") send("{ENTER 3}") send("sh dialer") send("{ENTER}") send("{SPACE 10}") exitloop else processclose($hwin) continueloop endif wend endfunc Link to comment Share on other sites More sharing options...
greenmachine Posted February 25, 2006 Share Posted February 25, 2006 What do you mean it returns 1? Do you mean that's the @error value after the WinGetText() call? Or is that the value of the variable $text, which means that's the text the WinGetText() function returned? Link to comment Share on other sites More sharing options...
monte Posted February 25, 2006 Author Share Posted February 25, 2006 help file states: Return Value Returns a string containing the window text read. Returns numeric 1 if no title match. When I ran my code my continueloop kept reocurring. So I put in $text = WinGetText("") sleep(500) msgbox(1,"",$text) to test and $text contains the numerical value 1. That tells me that wingettext is failing. I assumed the window text was to big and I checked. It's only 587 bytes. Not sure where to go from here. Link to comment Share on other sites More sharing options...
greenmachine Posted February 25, 2006 Share Posted February 25, 2006 What version are you using? My helpfile says: Failure: Returns numeric 0 if no title match. I'm using beta 3.1.1.106. Link to comment Share on other sites More sharing options...
GaryFrost Posted February 25, 2006 Share Posted February 25, 2006 (edited) help file states: Return Value Returns a string containing the window text read. Returns numeric 1 if no title match. When I ran my code my continueloop kept reocurring. So I put in $text = WinGetText("") sleep(500) msgbox(1,"",$text) to test and $text contains the numerical value 1. That tells me that wingettext is failing. I assumed the window text was to big and I checked. It's only 587 bytes. Not sure where to go from here. shouldn't this be? $text = WinGetTitle("") sleep(500) msgbox(0,"",$text) otherwise you need to supply at least the title for the param of WinGetText Edited February 25, 2006 by gafrost SciTE for AutoItDirections for Submitting Standard UDFs  Don't argue with an idiot; people watching may not be able to tell the difference.  Link to comment Share on other sites More sharing options...
greenmachine Posted February 25, 2006 Share Posted February 25, 2006 shouldn't this be? $text = WinGetTitle("") sleep(500) msgbox(0,"",$text) otherwise you need to supply at least the title for the param of WinGetText Since when gafrost? According to the helpfile, "Use WinGetText("") to get the active window's text." Link to comment Share on other sites More sharing options...
GaryFrost Posted February 25, 2006 Share Posted February 25, 2006 Since when gafrost? According to the helpfile, "Use WinGetText("") to get the active window's text." True, but if it's returning 1 then I would suggest putting in the title to make sure of getting text from the correct window. SciTE for AutoItDirections for Submitting Standard UDFs  Don't argue with an idiot; people watching may not be able to tell the difference.  Link to comment Share on other sites More sharing options...
monte Posted February 25, 2006 Author Share Posted February 25, 2006 I'm using version 3.1.1 gafrost and greenmachine: the msgbox function is only there for debugging purposes, in my real code I won't use it. My real problem is that in $mystr1=stringinstr($text,">",0,1), $text contains nothing and thus my following code never gets executed. Even when using $mytext=wingettitle("") or $mytext=wingettitle("telnet","") after I've winactivated, then executed $mystr1=stringinstr($mytext,">",0,1), my script still fails. Link to comment Share on other sites More sharing options...
greenmachine Posted February 25, 2006 Share Posted February 25, 2006 (edited) A little unrelated to the problem at hand, but I have a question - where does $vServer come from? I see this line -- $aMy[3]= $vServer -- but you never declare $vServer as anything. Oh right, I had another thing I wanted to say. Now that I realized you're using telnet, and that requires using the command prompt, I went and tried to get text from the cmd.exe. For one thing, no matter what I did I couldn't get it to return 1 or 0 or any number. It just returned "", an empty string. Since that was the case, I think that WinGetText does not work with the command prompt. Edited February 25, 2006 by greenmachine Link to comment Share on other sites More sharing options...
GaryFrost Posted February 25, 2006 Share Posted February 25, 2006 didn't cath this was trying to get text from telnet, might try searching for telnet SciTE for AutoItDirections for Submitting Standard UDFs  Don't argue with an idiot; people watching may not be able to tell the difference.  Link to comment Share on other sites More sharing options...
monte Posted February 25, 2006 Author Share Posted February 25, 2006 sorry about the $vServer statement, I was trying not to include all my code per easier reading. However, at the beginning of my router() is should read: $vServerClip=clipget() $vServerString=stringsplit($vServerClip,@TAB) If $vServerString[0] >= 22 Then $statuslabel = GUICtrlCreateLabel ("accessing router",0,220,350,16,BitOr($SS_SIMPLE,$SS_SUNKEN)) $vServer=$vServerString[22] ..... gafrost: I did that with $mytext=wingettitle("") and/or $mytext=wingettitle("telnet","") with no success. greenmachine, I agree with you that it just doesn't work. Even though I could get a return of 1. Thanks for all your help anyway! You guys are great. Link to comment Share on other sites More sharing options...
Moderators SmOke_N Posted February 25, 2006 Moderators Share Posted February 25, 2006 Ha!! Posted this in the wrong thread, anyway, If I am understanding you correctly, try this:$MyText = WinGetText(FindActiveWindow()) MsgBox(0, 'Test', $MyText) Func FindActiveWindow() Local $w_WinList = WinList() For $i = 1 to $w_WinList[0][0] If $w_WinList[$i][0] <> "" AND BitAnd(WinGetState($w_WinList[$i][1]), 2) _ And BitAnd(WinGetState($w_WinList[$i][1]), 8) Then Return $w_WinList[$i][0] Next EndFuncI'm assuming by you trying to use WinGetText("") that your trying to get the text from the active window. Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer. Link to comment Share on other sites More sharing options...
monte Posted February 25, 2006 Author Share Posted February 25, 2006 smoke_n: Thanks for the input, however it failed as well. the msgobx displays nothing. And, yes, I am trying to get the text from the active window ( specifically in a telnet session run from the dos command interpreter). Thanks though. Link to comment Share on other sites More sharing options...
Valuater Posted February 25, 2006 Share Posted February 25, 2006 maybe try this... dunno ; get Active Window (Title)(Text) ; Author - SmOke_N & Valuater $MyText = WinGetText(FindActiveWindow()) $MyTitle = WinGetTitle(FindActiveWindow()) MsgBox(0, $MyTitle, $MyText) Func FindActiveWindow() Opt("WinDetectHiddenText", 1) ;0=don't detect, 1=do detect Local $w_WinList = WinList() For $i = 1 to $w_WinList[0][0] If $w_WinList[$i][0] <> "" AND BitAnd(WinGetState($w_WinList[$i][1]), 2) _ And BitAnd(WinGetState($w_WinList[$i][1]), 8) Then Return $w_WinList[$i][0] Next Opt("WinDetectHiddenText", 0) ;0=don't detect, 1=do detect EndFunc 8) Link to comment Share on other sites More sharing options...
monte Posted February 25, 2006 Author Share Posted February 25, 2006 thanks SmOke_N & Valuater! The problem is the cmd window. This code works perfect for notepad, winword, wordpad...but fails with cmd window, not sure why. $mytext returns nothing! Thanks for the help though! I appreciate it. 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