Sign in to follow this  
Followers 0
JohnJF

Need help: ConsoleWrite not working

14 posts in this topic

Hi, I cannot get the following to work - print a text string to stdout:

ConsoleWrite("hello, world" & @CRLF)

When I run it (hello.au3) using winxp command console, nothing happens and it exits to the shell. Do I miss something?

Thanks for help! I did try to search the forum, but did not find anything to solve the issue. If it is already asked before, would appreciated the link.

Share this post


Link to post
Share on other sites



You must compile the script as a command line application to see it.

if you need to test very often you can run the script in scite using F5. the the printed text will be shown in the box under the source editing box. :D


Fuck 'em if they can't take a joke.

Share this post


Link to post
Share on other sites

Thanks! Running the following and then hello.exe solves the problem:

"c:\Program Files\AutoIt3\Aut2Exe\Aut2exe.exe" /in hello.au3 /out hello.exe /console

However, just wonder why running .au3 directly on cmd console does not work. It would be nice to have that feature: have to compile the script to use ConsoleWrite is not really convenient.

A follow-up question: can you (and if so how to) specify the command line arguments when running hello.au3 in the editor (your 2nd workaround)?

Share this post


Link to post
Share on other sites

You can use the following Au3Wrapper directive to run your exe as an console application:

#AutoIt3Wrapper_Change2CUI=Y
ConsoleWrite("Hello World" & @CRLF)

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites

JohnJF,

And you can run with parameters in SciTE by pressing "Shft-F8" or by using the <View - Parameters> menu item.

M23


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

Spoiler

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

But you still need to compile it and run the hello.exe, *not* hello.au3, right? I mean you cannot just add the line:

#AutoIt3Wrapper_Change2CUI=Y

and run hello.au3 and get the same result. I would prefer just have an .au3 file and run it on command line w/o any compile or other procedures. The interpreter seems not able to detect it is now running in console mode and print to stdout correctly.

Share this post


Link to post
Share on other sites

JohnJF,

And you can run with parameters in SciTE by pressing "Shft-F8" or by using the <View - Parameters> menu item.

M23

Cool! This will be handy. However, I still hope some future version can support the general command line usage, Shft-F8 only allows 4 args., this is really argc/argv in C program, and will make it easy to script and prototype.

Share this post


Link to post
Share on other sites

#8 ·  Posted (edited)

But you still need to compile it and run the hello.exe, *not* hello.au3, right? I mean you cannot just add the line:

#AutoIt3Wrapper_Change2CUI=Y

and run hello.au3 and get the same result. I would prefer just have an .au3 file and run it on command line w/o any compile or other procedures. The interpreter seems not able to detect it is now running in console mode and print to stdout correctly.

Its simple to explain as the AutoIt3.exe is compiled a GUI not a CUI.

Have you tried to compile a script as CUI and then use that script to run the script with by using this format:

Compiled.exe [/ErrorStdOut] [/AutoIt3ExecuteScript file] [params ...]

Jos

Edited by Jos

Visit the SciTE4AutoIt3 Download page for the latest versions        Beta files                                                          Forum Rules
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Share this post


Link to post
Share on other sites

Cool! This will be handy. However, I still hope some future version can support the general command line usage, Shft-F8 only allows 4 args., this is really argc/argv in C program, and will make it easy to script and prototype.

Just put multiple arguments in one box :D

Visit the SciTE4AutoIt3 Download page for the latest versions        Beta files                                                          Forum Rules
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Share this post


Link to post
Share on other sites

Its simple to explain as the AutoIt3.exe is compiled a GUI not a CUI.

Have you tried to compile a script as CUI and then use that script to run the script with by using this format:

Compiled.exe [/ErrorStdOut] [/AutoIt3ExecuteScript file] [params ...]

Jos

Can you give an example how to do this - how to write the compiled.au3? I assume then you can use the compiled.exe to run any .au3 script. This sounds to me that the compiled.au3/compiled.exe is the interpreter itself, but in CUI mode.

Share this post


Link to post
Share on other sites

#11 ·  Posted (edited)

Its pretty simple.

Stub Script (mystub.au3)

#Region ;**** Directives created by AutoIt3Wrapper_GUI ****
#AutoIt3Wrapper_UseUpx=n
#AutoIt3Wrapper_Change2CUI=y
#EndRegion ;**** Directives created by AutoIt3Wrapper_GUI ****
; CUI stub

Compile it.

test1.au3 script:

ConsoleWrite("hallo")

Now run this in the commandprompt:

mystub.exe /AutoIt3ExecuteScript test1.au3

Thats all,

Jos

Edited by Jos

Visit the SciTE4AutoIt3 Download page for the latest versions        Beta files                                                          Forum Rules
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Share this post


Link to post
Share on other sites

Hi Jos, this does work for my hello.au3. However, I run into issues with script using include, eg, the following:

#include <Array.au3>

ConsoleWrite("hello, world" & @CRLF)

$length = _ArraySize( $CmdLine )

ConsoleWrite("command line array length is: " & String($length))

Func _ArraySize( $aArray )

SetError( 0 )

$index = 0

Do

$pop = _ArrayPop( $aArray )

$index = $index + 1

Until @error = 1

Return $index - 1

EndFunc

Running the above pops up an error message, complaining that "Array.au3" cannot be opened. Do you know if this can be fixed?

Its pretty simple.

Stub Script (mystub.au3)

#Region ;**** Directives created by AutoIt3Wrapper_GUI ****
#AutoIt3Wrapper_UseUpx=n
#AutoIt3Wrapper_Change2CUI=y
#EndRegion ;**** Directives created by AutoIt3Wrapper_GUI ****
; CUI stub

Compile it.

test1.au3 script:

ConsoleWrite("hallo")

Now run this in the commandprompt:

mystub.exe /AutoIt3ExecuteScript test1.au3

Thats all,

Jos

Share this post


Link to post
Share on other sites

Running the above pops up an error message, complaining that "Array.au3" cannot be opened. Do you know if this can be fixed?

Should work fine when you put it in the same directory as the Autoit3.exe.

Jos


Visit the SciTE4AutoIt3 Download page for the latest versions        Beta files                                                          Forum Rules
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Share this post


Link to post
Share on other sites

Sweet - works now! Thanks for all the help and creating AutoIt! It is really cool and I guess I will sink lots of time into it :-)

Should work fine when you put it in the same directory as the Autoit3.exe.

Jos

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  
Followers 0