Jump to content

Why do apps have to be compiled for ConsoleWrite() to work from the command line?


Go to solution Solved by TheXman,

Recommended Posts

I understand the GUI/CUI issue.  
I’m just not understanding what compiling does to make ConsoleWrite work that the interpreter couldn’t do as well, based off the same or similar # directive the compiler uses.

Like command line switch to the interpreter like /console.

Or at the very worst, a separate executable.

If the reason is, “that’s just the way it is”, I’m ok with it.

Thoughts?

Code hard, but don’t hard code...

Link to comment
Share on other sites

Maybe I don't understand your question, but doesn't the following code work in all use cases: GUI or CUI, compiled or not?

CW("Hello world!" & @LF & "Μεγάλο πρόβλημα" & @LF & "Большая проблема" & @LF & "大问题" & @LF & "बड़ी समस्या" & @LF & "مشكلة كبيرة")
Sleep(5000)


Func CW($s = "")
    (@Compiled ? _CUI_ConsoleWrite : _ConsoleWrite)($s)
EndFunc   ;==>CW


Func _CUI_ConsoleWrite(ByRef $s)
    Local Static $hDll = DllOpen("kernel32.dll")
    Local Static $hCon = __CUI_ConsoleInit($hDll)
    DllCall($hDll, "bool", "WriteConsoleW", "handle", $hCon, "wstr", $s & @LF, "dword", StringLen($s) + 1, "dword*", 0, "ptr", 0)
    Return
EndFunc   ;==>_CUI_ConsoleWrite


; internal use only
Func __CUI_ConsoleInit(ByRef $hDll)
    DllCall($hDll, "bool", "AllocConsole")
    Return DllCall($hDll, "handle", "GetStdHandle", "int", -11)[0]
EndFunc   ;==>_CUI_ConsoleInit


; Unicode-aware ConsoleWrite
Func _ConsoleWrite($s)
    ConsoleWrite(BinaryToString(StringToBinary($s & @LF, 4), 1))
EndFunc   ;==>_ConsoleWrite

Depending on the font settings for CUI and Scite console, some language may not display correctly.
For instance Scite console displays everything correctly using Dejavu sans Mono.

Ignore me if you're after something else.

This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.
Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe here
RegExp tutorial: enough to get started
PCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta.

SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.
SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.
An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.
SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)
A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!
SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt)

Link to comment
Share on other sites

When you compile your au3 scripts with aut2exe, if you have a CUI directive in your script, it adds and uses a CUI stub to execute the embedded script.  So stdout goes directly to the console.  AutoIt3.exe and AutoIt3_x64 are actually GUI apps.  When you execute your au3 file using AutoIt3.exe or AutoIt3_x64.exe, you are actually executing it using GUI mode, regardless of the directive.

 

Edited by TheXman
Clarified that aut2exe adds a CUI stub if you have a CUI directive. Otherwise, it adds a GUI stub.
Link to comment
Share on other sites

Correct, but if you use my CW() function posted above, the output always gets sent to a console.

This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.
Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe here
RegExp tutorial: enough to get started
PCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta.

SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.
SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.
An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.
SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)
A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!
SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt)

Link to comment
Share on other sites

How to write the output to the console was not the question.  The question was why ...

Edited by TheXman
Link to comment
Share on other sites

OK I didn't mention myself that AutoIt3 exes were GUI because it was granted in my view.

This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.
Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe here
RegExp tutorial: enough to get started
PCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta.

SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.
SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.
An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.
SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)
A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!
SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt)

Link to comment
Share on other sites

1 minute ago, TheXman said:

How to write the output to the console was not the question.  The question was why ...

This is true.

Although, tbh, any reasonable way to write to the console from the interpreter is welcome information.

But, yes, I was wondering why...

And to your point that:

9 minutes ago, TheXman said:

AutoIt3.exe and AutoIt3_x64 are actually GUI apps.  When you execute your au3 file using AutoIt3.exe or AutoIt3_x64.exe, you are actually executing it using GUI mode, regardless of the directive.

That's what I assumed, until I considered the case where you use a compiled exe to run a script in interpretive mode.

In that case, even if the compiled script is compiled as a CUI, there is no console write output.

Code hard, but don’t hard code...

Link to comment
Share on other sites

  • Solution
23 minutes ago, JockoDundee said:

That's what I assumed, until I considered the case where you use a compiled exe to run a script in interpretive mode.

In that case, even if the compiled script is compiled as a CUI, there is no console write output.

That's odd.  I compiled a script that had the CUI=Y directive and the pragma that allows script execution.  I then used that compiled script from a cmd console to execute an au3 file, using the /Autoit3ExecuteScript switch.  The au3 file had several ConsoleWrites and all of them showed up in the cmd console.

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...