Jump to content

Running a3x in a CUI interface, output to stdout?


Recommended Posts

I've done some searching, and have not found what I'm looking for.

I have a number of small miscellaneous CUI programs I've compiled using ConsoleWrite() to provide status updates as the program runs. Compile to exe (with CUI setting), run or call from a batch file, and I can see what's happening as the program runs.

 

However, I've compiled the same programs to a3x. The programs seem to run as intended, but there is no output from ConsoleWtrite() statements. If run from a batch file, there is nothing on the batch file cmd window, if I run the .a3x file by double-clicking on it in file explorer, there is no console. 

 

Is there a way to sent text to a console for (CUI) a3x 'compiled' scripts?

Link to comment
Share on other sites

I ran into the same thing.

It doesn't look like a console compiled a3x is able to write to the console (tried on Win7 and Win10 x64).

I used this workaround.

;~** put this near beginning of program **
DllCall("kernel32.dll", "bool", "AllocConsole")
$hConsole = DllCall("kernel32.dll", "handle", "GetStdHandle", "int", -11)

;~** this is the function to call to write to the new console **
Func _cprint($str)
    $aRet = DllCall("kernel32.dll", "bool", "WriteConsoleW", "handle", $hConsole[0], "wstr", $str, "dword", StringLen($str), "dword*", 0, "ptr", 0)
EndFunc

;~** put this at the end of the program
DllCall("kernel32.dll","bool","FreeConsole")

;~** the message box is just used to hold the console window open, otherwise it will close after the program is done and you won't see anything
MsgBox(0, "done", "done")

This works good if you are running it on a desktop session, but if you are remote connected to another machine through a console, it won't work.

[font="Verdana"]People who say it cannot be done should not interrupt those who are doing it. - George Benard Shaw[/font]

Link to comment
Share on other sites

Thanks for the code! 

Looks it provides a way to easily replace my ConsoleWrite() statements in existing programs to be able to track activity when compiling to an a3x. It would be nice if I could write back to the 'parent' console, but I'll take what I can get!

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