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?
您还可以将以下编译器开关添加到脚本的顶部:
#pragma compile(Console, True)
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
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 .
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.