Print to console/command prompt
Asked Answered
C

3

6

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?

Curriery answered 13/1, 2016 at 8:7 Comment(2)
Are you using SciTE4AutoIt3?Sells
Matt is correct, when you run your script in SciTE you will have a Console output below.Novick
W
9

You can also add the following compiler switch to the top of your script:

#pragma compile(Console, True) 
Wisnicki answered 5/4, 2017 at 15:1 Comment(0)
N
6

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
Novick answered 13/1, 2016 at 22:12 Comment(0)
T
1

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:

    enter image description here

  • or press Ctrl + F7 (Tools > Compile), enable Create CUI instead of GUI EXE., then click Compile Script and run the resulting executable.

  • or add #AutoIt3Wrapper_Change2CUI=Y (or #pragma compile(Console, True)) to top of script, then press F7 (Tools > Build) and run the resulting executable.
  • or execute:
    ...\AutoIt3\Aut2Exe\Aut2exe.exe /in ...\script.au3 /out ...\script.exe /console
    and run the resulting executable.

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.

Tantalic answered 9/11, 2017 at 15:20 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.