zaphodikus Posted October 6, 2011 Posted October 6, 2011 The help document does not say anything about STDOUT handling at all, except that ConsoleWrite will NOT work as one might expect... (you have to compile????) So here starts my question, just plain simple: How do I debug a script using "print" like statements? String handling in autoIT is very easy, and writing debug appears to not only be ideal, but also powerful, so why is it so hard to send something to STDOUT? STDOUT is also an idea vehicle for me, for remote or parallel execution of scripts. I could debug using messageboxes, but that would be troll, or I could using a temporary file and WriteFile(file, data) - but then things like relative-pathing and creating temp files become a question. So, since the intuitive function ConsoleWrite (data) behaves differently depending on some options I have not yet discovered (I think this is obvious to my audience by now) how do I proceed (assuming I have a maximum of 30 minutes before getting bored) what do most coders do to reliably debug? (Since I'm a beginner, I am not yet up to speed with why or how to compile, and from previous programming experience know that compiling is evil if you have a fast processor and a fast parser.)
BrewManNH Posted October 6, 2011 Posted October 6, 2011 ConsoleWrite works whether the script is compiled or not.If you're looking to access StdOutRead/StdInWrite, you should be using those commands but they only work on a process that you run with a script, the script itself uses ConsoleWrite/Read to send and receive from those streams. If you haven't done so already, download the full Scite4AutoIt3 package and use some of the debugging tools that are in the tools menu of Scite, such as debug to console, and run your script from SciTE. 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
Moderators Melba23 Posted October 6, 2011 Moderators Posted October 6, 2011 zaphodikus, Welcome to the AutoIt forum. You certainly do not need to compile to use ConsoleWrite - it is designed to be used within the SciTE editor where the output appears in the lower pane. I debug using a combination of the following: - ConsoleWrite (which does not pause the script)- _ArrayDisplay and MsgBox (which do pause it)- #AutoIt3Wrapper_Run_Debug_Mode (which actually shows the lines being run in the SciTE console) - for this you need the full SciTE4AutoIt3 download.There is also a graphical debugger in the Examples forum but I have never used it (nor found the need). Any help? M23 Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area
Spiff59 Posted October 6, 2011 Posted October 6, 2011 (edited) Tooltip() is another command useful as a quick-and-dirty way of displaying values or trace/status information Edited October 6, 2011 by Spiff59
Ascend4nt Posted October 6, 2011 Posted October 6, 2011 Simplest way, other than using an output GUI or notepad or somesuch is using a forced Console. This code only creates a Console if run from *outside* of SciTE: Global $hConsole=0 DllCall("kernel32.dll","bool","AllocConsole") $aRet=DllCall("kernel32.dll","handle","GetStdHandle","int",-11) If Not @error Then $hConsole=$aRet[0] $sOutput="Console Output" ConsoleWrite("SciTE or Command-line Console Output"&@CRLF) If $hConsole Then DllCall("kernel32.dll","bool","WriteConsoleW","handle",$aRet[0],"wstr",$sOutput,"dword",StringLen($sOutput),"dword*",0,"ptr",0) Sleep(2000) DllCall("kernel32.dll","bool","FreeConsole") EndIf Obviously putting all this inside functions is preferable. (I have a Console UDF lying around but its messy) My contributions: Performance Counters in Windows - Measure CPU, Disk, Network etc Performance | Network Interface Info, Statistics, and Traffic | CPU Multi-Processor Usage w/o Performance Counters | Disk and Device Read/Write Statistics | Atom Table Functions | Process, Thread, & DLL Functions UDFs | Process CPU Usage Trackers | PE File Overlay Extraction | A3X Script Extract | File + Process Imports/Exports Information | Windows Desktop Dimmer Shade | Spotlight + Focus GUI - Highlight and Dim for Eyestrain Relief | CrossHairs (FullScreen) | Rubber-Band Boxes using GUI's (_GUIBox) | GUI Fun! | IE Embedded Control Versioning (use IE9+ and HTML5 in a GUI) | Magnifier (Vista+) Functions UDF | _DLLStructDisplay (Debug!) | _EnumChildWindows (controls etc) | _FileFindEx | _ClipGetHTML | _ClipPutHTML + ClipPutHyperlink | _FileGetShortcutEx | _FilePropertiesDialog | I/O Port Functions | File(s) Drag & Drop | _RunWithReducedPrivileges | _ShellExecuteWithReducedPrivileges | _WinAPI_GetSystemInfo | dotNETGetVersions | Drive(s) Power Status | _WinGetDesktopHandle | _StringParseParameters | Screensaver, Sleep, Desktop Lock Disable | Full-Screen Crash Recovery Wrappers/Modifications of others' contributions: _DOSWildcardsToPCRegEx (original code: RobSaunder's) | WinGetAltTabWinList (original: Authenticity) UDF's added support/programming to: _ExplorerWinGetSelectedItems | MIDIEx UDF (original code: eynstyne) (All personal code/wrappers centrally located at Ascend4nt's AutoIT Code)
zaphodikus Posted October 6, 2011 Author Posted October 6, 2011 solved! Thanks a stack - that explains the little implementation note for ConsoleWrite(). So the SCiTE editor actually compiles my script - I was not using the IDE, (because I prefer to use my favourite editor for as many tasks as as possible). When I did use CSiTE I could see my ConsoleWrite() output, hence it seemed natural the commandline would be identical to the editor. Because of my useage pattern, and the fact that when I'm mostly executing a script remotely I cannot use the SCiTE editor in such case. So the example showing grabbing the STDOUT handle and 'brutally' :-) writing to it, which I could wrap nicely in a console msg with 4 arguments Func ConsoleDebugString( $scriptfileName, $linenumber, $msglevel, $message ) This approach also gives me flexibility in the case where my "boss" wants an audit log saved to a file suddenly. At the moment my use of AutoIT is just maintenance, I just need to become sensitive to the AutoIT coding standards and script writing guidelines next. ... I am suspecting I might rather enjoy using autoIT going forward.
zaphodikus Posted October 6, 2011 Author Posted October 6, 2011 (edited) After playing with AllocConsole() and inspecting the standard handles it got clearer. :-) :-) :-) AutoIT.exe is a windowless process, not a console process. So what I really want is logging/tracing to a file, and then to "tail" the file in the code that does my remoting - my best bet is to pass in the log filename as an argument to the script to allow duplicates/parallel execution. 1. create a temp file 2. spawn thread to read/tail the tmp file 3. call the autoit binary and script with the name of the tmp file 4. delete the tmp file and by proxy the thread too start_teabreak() Edited October 6, 2011 by zaphodikus
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