Jump to content

ConsoleWrite not working on compiled executable


Go to solution Solved by SadBunny,

Recommended Posts

Environment: Windows 7 64-bit, AutoIt installed to use x86 version by default.

Tried compiling and executing for both x64 and x86, no difference. Came across this post in debugging:

'?do=embed' frameborder='0' data-embedContent>>

Following the advice from that post, here is my code snippet, say I name it "test.au3" for example

#Region ;**** Directives created by AutoIt3Wrapper_GUI ****
#AutoIt3Wrapper_UseUpx=n
#AutoIt3Wrapper_Change2CUI=y
#EndRegion ;**** Directives created by AutoIt3Wrapper_GUI ****
; CUI stub
ConsoleWrite("start" & @CRLF)
While WinExists("Adobe Illustrator CS5") <> 1
    If WinExists("Script Alert") Then
        ConsoleWrite(WinGetText("Script Alert") & @CRLF)
        Exit
    EndIf
WEnd
ConsoleWrite("AI script done!" & @CRLF)

When run as compiled exe from command line, e.g. "C:SomeFolder>test.exe", I see no output. For both x86 and x64 compiled versions (run from x64 and x86 command prompts).

But I do see output from Scite editor using F5. The Scite output appears to show the command executed as well, something like:

"C:Program Files (x86)AutoIt3SciTE..autoit3.exe" /ErrorStdOut "C:SomeFoldertest.au3"

Executing same command parameters in command prompt doesn't print the same output to the command prompt. Nothing gets printed.

I don't want to view output just in Scite but in command prompt. What's the issue here? I'm stumped.

Also, no difference if I just had #AutoIt3Wrapper_Change2CUI=y directive only w/o the other one.

Link to comment
Share on other sites

  • Solution

From the helpfile of ConsoleWrite:

This does not write to a DOS console unless the script is compiled as a console application.

Onwards to the helpfile text on "Compiling Scripts with Aut2Exe", which tells us that we can run the Aut2Exe compiler with the /console switch to make is a console application. If you are running from SciTE, you can just press ctrl+F7, which will bring up the Compile dialog, and check the "Create CUI instead of GUI EXE" checkbox before you press the "Compile Script" button.

Works on my ConsoleWrite'ing hello world testscript

Roses are FF0000, violets are 0000FF... All my base are belong to you.

Link to comment
Share on other sites

Do you have the full version of SciTE4AutoIt3 installed? Without having downloaded and installed that, the line #AutoIt3Wrapper_Change2CUI=Y  won't do anything because the AutoIt3Wrapper.exe isn't installed without it.

If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Link to comment
Share on other sites

Do you have the full version of SciTE4AutoIt3 installed? Without having downloaded and installed that, the line #AutoIt3Wrapper_Change2CUI=Y  won't do anything because the AutoIt3Wrapper.exe isn't installed without it.

 

Ah, missed that directive in the code entirely :) Well, it modifies the same behaviour as my suggestions.

Roses are FF0000, violets are 0000FF... All my base are belong to you.

Link to comment
Share on other sites

Ah, missed that directive in the code entirely :) Well, it modifies the same behaviour as my suggestions.

Correct. Just wanted to make sure the OP was using the directive correctly. Without having AutoIt3Wrapper available, he may have thought it was being compiled correctly, when in fact it wasn't. :)

If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Link to comment
Share on other sites

From the helpfile of ConsoleWrite:

This does not write to a DOS console unless the script is compiled as a console application.

Onwards to the helpfile text on "Compiling Scripts with Aut2Exe", which tells us that we can run the Aut2Exe compiler with the /console switch to make is a console application. If you are running from SciTE, you can just press ctrl+F7, which will bring up the Compile dialog, and check the "Create CUI instead of GUI EXE" checkbox before you press the "Compile Script" button.

Works on my ConsoleWrite'ing hello world testscript

 

Thanks, didn't know that. I was using the standard compile option in Scite (no compile dialog, just hit menu option), as well as the right-click option of the Explorer shell integration to compile for x86 or x64. I assume those methods will compile to GUI rather than CUI?

I wish this was all documented more clearly. The info info should have been cross-linked/reference on the ConsoleWrite docs so I don't have to specifically search for this help info elsewhere in the AutoIt docs. Before this I never knew there was a difference between CUI vs GUI for AutoIt compilations.

Link to comment
Share on other sites

  • Developers

Thanks, didn't know that. I was using the standard compile option in Scite (no compile dialog, just hit menu option), as well as the right-click option of the Explorer shell integration to compile for x86 or x64. I assume those methods will compile to GUI rather than CUI?

It is an Add-on I made over the last "many" years and comes in a separate installer. Jon only included at some point the Lite version of SciTE in the AutoIt3 installer.

There is no need to do Ctrl+f7 as lonmg as yet have the #AutoIt3Wrapper directive in the source.

Not sure I understand your last question.

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

It is an Add-on I made over the last "many" years and comes in a separate installer. Jon only included at some point the Lite version of SciTE in the AutoIt3 installer.

There is no need to do Ctrl+f7 as lonmg as yet have the #AutoIt3Wrapper directive in the source.

Not sure I understand your last question.

Jos

 

I meant that compiling (or building) from Scite did not produce an exe that writes to stdout. And compiling from the explorer right-click context menu compile options did not produce the right exe either even though it has the directive line of code in the au3 script. Using Aut2Exe.exe with the console switch did the trick.

By the way, I have the lite Scite version bundled with the AutoIt installer package. I don't really care for Scite, I just wanted to compile the exe, just mentioned Scite here in terms of my observations on what happens. So from the discussions here, I take it only the full Scite can compile CUIs and not the lite Scite version?

I don't know if it makes sense, but it may be helpful to add a compile to CUI option in the Explorer right-click context menu option for AutoIt. Less hassle than to have to do:

"C:\Program Files (x86)\AutoIt3\Aut2Exe\Aut2exe.exe" /in test.au3 /console

Edited by daluu
Link to comment
Share on other sites

  • Developers

The #AutoIt3Wrapper directives will only work when you use the full version of SciTE4AutoIt3 as that comes with AutoIt3Wrapper which performs all the extra tasks.

The standard setup indeed doesn't have the CUI option unless you start aut2exe and set it manually.

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

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