Jump to content

Need help: ConsoleWrite not working


JohnJF
 Share

Recommended Posts

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.

Link to comment
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.

Link to comment
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)?

Link to comment
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 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to comment
Share on other sites

  • Moderators

JohnJF,

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

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png 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 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

 

Link to comment
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.

Link to comment
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.

Link to comment
Share on other sites

  • Developers

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

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Link to comment
Share on other sites

  • Developers

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

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Link to comment
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.
Link to comment
Share on other sites

  • Developers

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

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Link to comment
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

Link to comment
Share on other sites

  • Developers

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

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...