Jump to content

Write to Console for GUI-Based Applications


DJKMan
 Share

Recommended Posts

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.

 

 

Link to comment
Share on other sites

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
Link to comment
Share on other sites

  • 2 weeks later...

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