Jump to content
Sign in to follow this  
DJKMan

Write to Console for GUI-Based Applications

Recommended Posts

DJKMan

I'm not sure if someone posted an example like mine already but feel free to let me know. I did search around and only found people using hacks to make it work.

This is very simple and can be incorporated into any projects without an include. This is AutoIt with batch. As simple as I can get.

Compile this into a Example.exe:

#Region ;**** Directives created by AutoIt3Wrapper_GUI ****
#AutoIt3Wrapper_Outfile=Example.exe
#EndRegion ;**** Directives created by AutoIt3Wrapper_GUI ****
;Consolewrite for GUI-Based Apps Example by DJKMan
Local $sleep=3000
ConsoleWrite("echo Hello World!" & @LF) ;Echo first line.

While 1
    $randomnumber = Random(1, 5, 1)
    ConsoleWrite("echo Random Number: " & $randomnumber &@LF);Echo random number to console
    ConsoleWrite("echo ---Sleeping: "&$sleep&"---"&@LF)
    Sleep($sleep)
WEnd

Then save this as DevConsole.cmd and place it in the same directory as Example.exe:

@echo off
title Example System - Developer Console
Prompt $G
color 03
"Example.exe"|cmd.exe /Q

Run DevConsole.cmd and that's all there is to it. Hope this helps you on your projects.


My work in AutoIt (Not many yet):

Parse Large Text Files To 2D Array Quickly [With Chunk Size]

 

My artificial intelligence project coded entirely in AutoIt. Meet Alice Assistant: http://facebook.com/ProjectAliceAI

 

Share this post


Link to post
Share on other sites
wraithdu

EDIT - better solution.

Neat idea. Here's without the batch file. It gets a little funny if you're dealing with command line params, but you get the idea.

#Region ;**** Directives created by AutoIt3Wrapper_GUI ****
#AutoIt3Wrapper_Outfile=Example.exe
#EndRegion ;**** Directives created by AutoIt3Wrapper_GUI ****
;Consolewrite for GUI-Based Apps Example by DJKMan

Global $DEBUG = True

If $DEBUG Then _ConsoleDebugRun()

Func _ConsoleDebugRun()
    DllCall("kernel32.dll", "handle", "CreateMutexW", "ptr", 0, "bool", 1, "wstr", "AutoItDeveloperConsoleMutex")
    If @error Then Return SetError(1)
    Local $lastErr = DllCall("kernel32.dll", "dword", "GetLastError")
    If @error Then Return SetError(2)
    If $lastErr[0] <> 183 Then ; ERROR_ALREADY_EXISTS
        Run(@ComSpec & ' /c @echo off && title Example System - Developer Console && prompt $G && color 03 && "' & _
            @ScriptFullPath & '" ' & $CmdLineRaw & ' | ' & @ComSpec & ' /Q')
            Sleep(3000) ; give time to launch child
        Exit
    EndIf
EndFunc

Local $sleep=3000
ConsoleWrite("echo Hello World!" & @LF) ;Echo first line.

While 1
    $randomnumber = Random(1, 5, 1)
    ConsoleWrite("echo Random Number: " & $randomnumber &@LF);Echo random number to console
    ConsoleWrite("echo ---Sleeping: "&$sleep&"---"&@LF)
    Sleep($sleep)
WEnd
Edited by wraithdu
  • Like 1

Share this post


Link to post
Share on other sites
wraithdu

I edited with a better solution using a mutex. No confusion with command line params this way.

Share this post


Link to post
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
Sign in to follow this  

×