Jump to content
Sign in to follow this  

Debugging using ConsoleWrite?

Recommended Posts


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.)

Share this post

Link to post
Share on other sites

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 Gude
How 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

Share this post

Link to post
Share on other sites


Welcome to the AutoIt forum. :graduated:

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? ;)


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______My UDFs:


ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area


Share this post

Link to post
Share on other sites

Tooltip() is another command useful as a quick-and-dirty way of displaying values or trace/status information

Edited by Spiff59

Share this post

Link to post
Share on other sites

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
If Not @error Then $hConsole=$aRet[0]
$sOutput="Console Output"
ConsoleWrite("SciTE or Command-line Console Output"&@CRLF)
If $hConsole Then

Obviously putting all this inside functions is preferable. (I have a Console UDF lying around but its messy)

Share this post

Link to post
Share on other sites


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.

Share this post

Link to post
Share on other sites

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


Edited by zaphodikus

Share this post

Link to post
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
Sign in to follow this