ywangperl Posted April 15, 2014 Share Posted April 15, 2014 The following code has the Run("notepad.exe") commented. I expect the code will wait till I manually start notepad. But the scprit exits without waiting (this is *NOT* expected). If I start a notepad and run the script, the script works fine. I have spent hours on it without success. Please help! -Y -------------------------------- autoIt example doesn't work for me------------------------------ Example() Func Example() ; Run Notepad ;Run("notepad.exe") ; Wait 10 seconds for the Notepad window to appear. WinWait("[CLASS:Notepad]", "", 10000) ; Wait for 2 seconds to display the Notepad window. Sleep(2000) ; Close the Notepad window using the classname of Notepad. WinClose("[CLASS:Notepad]") EndFunc ;==>Example Link to comment Share on other sites More sharing options...
somdcomputerguy Posted April 15, 2014 Share Posted April 15, 2014 change the 10000 to 10, run the script again, then re-read the Help file.. - Bruce /*somdcomputerguy */ If you change the way you look at things, the things you look at change. Link to comment Share on other sites More sharing options...
DW1 Posted April 15, 2014 Share Posted April 15, 2014 Your script is working as expected for me. What version of autoit are you running, and do you have any instances of notepad running that you missed? AutoIt3 Online Help Link to comment Share on other sites More sharing options...
jdelaney Posted April 15, 2014 Share Posted April 15, 2014 (edited) Don't include any third param if you want to wait forever for the window...click this link: winwait Also, are you expecting only new instances to be closed? You'll need to script for that. The example closes the first instance of a window with class = notepad. Edited April 15, 2014 by jdelaney IEbyXPATH-Grab IE DOM objects by XPATH IEscriptRecord-Makings of an IE script recorder ExcelFromXML-Create Excel docs without excel installed GetAllWindowControls-Output all control data on a given window. Link to comment Share on other sites More sharing options...
ywangperl Posted April 15, 2014 Author Share Posted April 15, 2014 Thanks for the answer. Here are the commands that I have tried on 2 PCs (v3.3.10.2). I am expecting the code will wait forever. But6 is is not happening. Confused -Y Example() Func Example() ;WinWait("[CLASS:NotepadNotExist]", "", 10) WinWait("[CLASS:NotepadNotExist]") EndFunc ;==>Example Link to comment Share on other sites More sharing options...
somdcomputerguy Posted April 15, 2014 Share Posted April 15, 2014 (edited) I am running a slightly older version than you (3.3.8.1), so maybe that has something to do with something, but when I ran this line of code:WinWait("[CLASS:NotepadNotExist]", "", 10)the script exited about 10 seconds after I started it. I ran this line of code:WinWait("[CLASS:NotepadNotExist]")and after about a minute and a half I manually stopped the script. Edited April 15, 2014 by somdcomputerguy - Bruce /*somdcomputerguy */ If you change the way you look at things, the things you look at change. Link to comment Share on other sites More sharing options...
jdelaney Posted April 16, 2014 Share Posted April 16, 2014 Run this: $hwnd = WinWait("[CLASS:NotepadNotExist]") Consolewrite($hwnd & @crlf) post back the output. IEbyXPATH-Grab IE DOM objects by XPATH IEscriptRecord-Makings of an IE script recorder ExcelFromXML-Create Excel docs without excel installed GetAllWindowControls-Output all control data on a given window. Link to comment Share on other sites More sharing options...
ywangperl Posted April 16, 2014 Author Share Posted April 16, 2014 Something is very wrong. This following script won't print anything, no matter if there is a notepad indtance. Local $sString = "running autoIt" ConsoleWrite($sString & @CRLF) $hwnd = WinWait("[CLASS:NotepadNotExist]") Consolewrite($hwnd & @crlf) $hwnd = WinWait("[CLASS:Notepad]") Consolewrite($hwnd & @crlf) Link to comment Share on other sites More sharing options...
BrewManNH Posted April 16, 2014 Share Posted April 16, 2014 What program has a class of NotepadNotExist? Notepad.exe uses Class:Notepad, so I'm not sure what it is you're attempting to do here. If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag GudeHow to ask questions the smart way! I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from. Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays. - ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script. - Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label. - _FileGetProperty - Retrieve the properties of a file - SciTE Toolbar - A toolbar demo for use with the SciTE editor - GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI. - Latin Square password generator Link to comment Share on other sites More sharing options...
somdcomputerguy Posted April 16, 2014 Share Posted April 16, 2014 I'm pretty sure that weird classname was just to test the functionality of the WinWait function. - Bruce /*somdcomputerguy */ If you change the way you look at things, the things you look at change. Link to comment Share on other sites More sharing options...
somdcomputerguy Posted April 16, 2014 Share Posted April 16, 2014 Hmm.. If I run this code:Run("notepad.exe") Local $sString = "running autoIt" ConsoleWrite($sString & @CRLF) $hwnd = WinWait("[CLASS:NotepadNotExist]", "", 1) Consolewrite($hwnd & @crlf) $hwnd = WinWait("[CLASS:Notepad]", "", 1) Consolewrite($hwnd & @crlf)I get this:running autoIt 0 0x0013054AIf I run this code:Local $sString = "running autoIt" ConsoleWrite($sString & @CRLF) $hwnd = WinWait("[CLASS:NotepadNotExist]") Consolewrite($hwnd & @crlf) $hwnd = WinWait("[CLASS:Notepad]") Consolewrite($hwnd & @crlf)I get this:running autoItand the script will keep running (doing nothing because WinWait waits forever for a program with a classname of NotepadNotExist) until I manually end it. - Bruce /*somdcomputerguy */ If you change the way you look at things, the things you look at change. Link to comment Share on other sites More sharing options...
BrewManNH Posted April 16, 2014 Share Posted April 16, 2014 I'm pretty sure that weird classname was just to test the functionality of the WinWait function. Yeah, I'm not paying very good attention here. I ran the test scripts and they work just fine for me as well, running it on 3.3.11.3. WinWait is waiting when I try it. If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag GudeHow to ask questions the smart way! I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from. Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays. - ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script. - Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label. - _FileGetProperty - Retrieve the properties of a file - SciTE Toolbar - A toolbar demo for use with the SciTE editor - GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI. - Latin Square password generator Link to comment Share on other sites More sharing options...
somdcomputerguy Posted April 16, 2014 Share Posted April 16, 2014 Yeah, I'm not paying very good attention here. I ran the test scripts and they work just fine for me as well, running it on 3.3.11.3. WinWait is waiting when I try it.They're working fine and as I expect them too, with the older version I run. - Bruce /*somdcomputerguy */ If you change the way you look at things, the things you look at change. Link to comment Share on other sites More sharing options...
jdelaney Posted April 16, 2014 Share Posted April 16, 2014 Something is very wrong. This following script won't print anything, no matter if there is a notepad indtance. Local $sString = "running autoIt" ConsoleWrite($sString & @CRLF) $hwnd = WinWait("[CLASS:NotepadNotExist]") Consolewrite($hwnd & @crlf) $hwnd = WinWait("[CLASS:Notepad]") Consolewrite($hwnd & @crlf) What do you think is 'wrong' here...you will never find a window with that class=NotepadNotExist, one does not exist...and there is no timeout, so youre deadlocked...what do you expect to occur? AutoIT is linear, so you must fulfill the first winwait prior to executing the second winwait. IEbyXPATH-Grab IE DOM objects by XPATH IEscriptRecord-Makings of an IE script recorder ExcelFromXML-Create Excel docs without excel installed GetAllWindowControls-Output all control data on a given window. Link to comment Share on other sites More sharing options...
ywangperl Posted April 16, 2014 Author Share Posted April 16, 2014 Something is *wrong* on that script. The script just "exit" to Dos prompt. Nothing happened. When I get home I tried this sample using (v3.3.8.1). Nothing is printed to stdout. Local $var = "Test" ConsoleWrite("var=" & $var & @CRLF) Thank everyone for your time and attention. I am stuck on this:(. Problem 1: ConsoleWrite doesn't work. Problem 2: WinWait exitd when the window doesn't exist. If anyone has a wild guess, please share it with me. (They happended on 2 PC at work and one PC at home) -Y Link to comment Share on other sites More sharing options...
JohnOne Posted April 16, 2014 Share Posted April 16, 2014 Are you running it with #RequireAdmin? If you are script will appear to exit in scite while infact a new instance has been spawned. Explain how you are actually running it because "The script just "exit" to Dos prompt" suggests you are starting it from that. AutoIt Absolute Beginners Require a serial Pause Script Video Tutorials by Morthawt ipify Monkey's are, like, natures humans. Link to comment Share on other sites More sharing options...
ywangperl Posted April 16, 2014 Author Share Posted April 16, 2014 Note1: w is an Administrator c:_TAF>whoami w c:_TAF>cat e2.au3 Local $var = "Test" ConsoleWrite("var=" & $var & @CRLF) c:_TAF>"c:Program Files (x86)AutoIt3AutoIt3.exe" e2.au3 c:_TAF> Note 2: nothing get printed. Link to comment Share on other sites More sharing options...
JohnOne Posted April 16, 2014 Share Posted April 16, 2014 Nothing will be written to console window when running exe like that. Unless there is something else relevant about your script you should add. If so, why not explain everything instead of needing it dragged out. AutoIt Absolute Beginners Require a serial Pause Script Video Tutorials by Morthawt ipify Monkey's are, like, natures humans. Link to comment Share on other sites More sharing options...
ywangperl Posted April 16, 2014 Author Share Posted April 16, 2014 Story: Problem 1: the WinWait wont' wait for the notepad (When there is no notepad window, the script exit to DOS promptly) I tried to WinWait an non-existing window and hoping the script will "wait". But the script exists to DOS right away Problem 2: To debug, I used ConsoleWrite to print STDOUT. But nothing get printed to STDOUT. Both WinWait and ConsoleWrite are simple comands and they don't work for me. I am asking for help here. Thanks again -Y Link to comment Share on other sites More sharing options...
jdelaney Posted April 16, 2014 Share Posted April 16, 2014 (edited) How are you initiating the script...post back the actual command as well. If it's not compiled as a console app, and you are running through a console, there will be no output. You can do file writes instead. FileWrite Edited April 16, 2014 by jdelaney IEbyXPATH-Grab IE DOM objects by XPATH IEscriptRecord-Makings of an IE script recorder ExcelFromXML-Create Excel docs without excel installed GetAllWindowControls-Output all control data on a given window. 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