Reputation: 3233
I want to write text to console/Windows command prompt in AutoIt. I made a test script as shown below:
Func Test()
ConsoleWrite("Hello")
EndFunc
Test()
I saved the script as test.au3
. When I run it, it does not print to console. I checked ConsoleWrite()
; it should print to DOS console if it the script is compiled as a console application.
I compiled the script using Aut2Exe. It still does not print to console. How do I write to console in AutoIt?
Upvotes: 6
Views: 11404
Reputation: 3002
How do I write to console in AutoIt?
As per Documentation - Function Reference - ConsoleWrite()
:
The purpose for this function is to write to the STDOUT stream. … Scripts compiled as Console applications also have a STDOUT stream.
Save script as .au3
file, then:
press F5 (Tools > Go) in editor. Console output will be displayed in the editor's lower pane:
or press Ctrl + F7 (Tools > Compile), enable Create CUI instead of GUI EXE.
, then click Compile Script
and run the resulting executable.
#AutoIt3Wrapper_Change2CUI=Y
(or #pragma compile(Console, True)
) to top of script, then press F7 (Tools > Build) and run the resulting executable....\AutoIt3\Aut2Exe\Aut2exe.exe /in ...\script.au3 /out ...\script.exe /console
I compiled the script using Aut2Exe. It still does not print to console.
For compiled scripts a console window is visible during runtime only. Example:
#AutoIt3Wrapper_Change2CUI=Y
Global Enum $EXITCODE_OK
Global Const $g_sMsg = 'Hello, World!' & @CRLF
Global Const $g_iDelay = 1000 * 10
Main()
Func Main()
ConsoleWrite($g_sMsg)
Sleep($g_iDelay)
Exit $EXITCODE_OK
EndFunc
Related: Console and graphical user interface.
Upvotes: 1
Reputation: 141
You can also add the following compiler switch to the top of your script:
#pragma compile(Console, True)
Upvotes: 9
Reputation: 1707
Just compile your test.au3 like this:
%PathToAutoItVersion%\Aut2Exe\Aut2exe.exe /in test.au3 /out test.exe /console
And then you can Run test.exe
and it will print out:
hello
Upvotes: 6