Jump to content

AutoIt Console Application


Recommended Posts

Local $sAnswer = InputBox(" ", "Write your name:", "", "", 404, 136, Default, Default, 120)
MsgBox(0,"","Nice to meet you "&$sAnswer)

How convert this code into a console?
Print the question and wait for answers from the user in the console window that is not INPUT BOX?

 

ConsoleWrite("Write your name:" &@CRLF)
ConsoleWrite("Nice to meet you: " & $sAnswer &@CRLF)

 

Regards,
 

Link to comment
Share on other sites

Freely adapted from the helpfile of ConsoleRead. Notice that it should be ran as a compiled exe, and be compiled as a console application (otherwise ConsoleWrite will not write to the dos screen).

Use the SciTE compile dialog (Ctrl+F7, check option Create CUI instead of GUI EXE ), or the /console switch to if you command the compiler from the commandline.

Run by piping the standard input of the shell session (descriptor CON) to the command, by literally doing this: type CON | myapplication.exe (of course changing the application name to your own).

#Region ;**** Directives created by AutoIt3Wrapper_GUI ****
#AutoIt3Wrapper_Change2CUI=y
#EndRegion ;**** Directives created by AutoIt3Wrapper_GUI ****

#include <MsgBoxConstants.au3>

Example()

Func Example()
    If Not @Compiled Then
        MsgBox($MB_SYSTEMMODAL, "", "This script must be compiled in order to run the example.")
        Exit
    EndIf

    ConsoleWrite("Enter your name. Enter ^Z on a new line when you're done (equals EOF)." & @CRLF & "Name: ")

    Local $sOutput

    While True
        $sOutput &= ConsoleRead()
        If @error Then ExitLoop
        Sleep(25)
    WEnd

    ; DOS only recognizes the EOF command when it's at the start of a line, meaning the last character is always a newline
    While StringRegExp(StringRight($sOutput, 1), "[\r\n]")
        $sOutput = StringTrimRight($sOutput, 1)
    WEnd

    ConsoleWrite("Name received: '" & $sOutput & "'")
EndFunc   ;==>Example

 

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

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