Jump to content

how to make console application


Recommended Posts

can autoit make console applications such as basic xcopy or instsrv like those that if u just double click in them they would do nothign because they only accept command's given my CMD or batch files or such.

Can u guys give me one example of show me link where those referenced to ?

THanks in advance

Link to comment
Share on other sites

Search "Command Line Parameters" to see how to use $cmdline to read values passed from the commandline.

See Consolewrite() to output to Stdout

And add:

#AutoIt3Wrapper_Change2CUI=y

To the top of your script so that when compiled it will be read as a console application and dump Stdout to the console window that started it.

Link to comment
Share on other sites

My version of a word count command line filter. Compile, run from a cmd window, see msgbox for instructions.

#AutoIt3Wrapper_Change2CUI=y
#include <Array.au3>

$vCnt = 1
Do
    $aInp = StringRegExp(StringReplace(ConsoleRead(), Chr(0), ""), "(?i)(\b[a-z'?-?_]{2,}\b|\ba\b|\bi\b)", 3)
    $vCnt += UBound($aInp) -1
    ConsoleWrite(_ArrayToString($aInp, @CRLF))
Until Not ConsoleRead(0, 1)

Select
    Case Not IsArray($aInp)
        MsgBox(262144, @ScriptName, _
              "No input file provided or no words found" & @LF & @LF _
            & "List words to command line: " & @TAB & @ScriptName & " < somefile.ext" & @TAB & @LF _
            & "Redirect to a file: " & @TAB & @TAB &  @ScriptName & " < somefile.ext > output.txt" & @TAB & @LF _
            & "List words with count: " & @TAB &  @ScriptName & " < somefile.ext  w" & @TAB)
    Case $cmdline[0] > 0
        If $cmdline[1] = "w" Then
            ConsoleWrite(@CRLF & @CRLF & "Word count = " & $vCnt)
            MsgBox(262144, @ScriptName, "Word count = " & $vCnt)
        EndIf
EndSelect

Link to comment
Share on other sites

  • Developers

can autoit make console applications such as basic xcopy or instsrv like those that if u just double click in them they would do nothign because they only accept command's given my CMD or batch files or such.

Can u guys give me one example of show me link where those referenced to ?

THanks in advance

Since when will console applications not work when you double click them?

The only reason some "seem" to do nothing is because they require command line parameters and will stop executing when they are omitted.

Jos

PS: merged double posting

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

  • Developers

most of them dont so i thought its kinda common thing for console apps so i wanted to get that covered.

Seems like you are still convinced that console applications not run when you double click them?

I do not know of any that doesn't run but plenty that will open a CMD window that very briefly displays an error and than close.

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

Seems like you are still convinced that console applications not run when you double click them?

I do not know of any that doesn't run but plenty that will open a CMD window that very briefly displays an error and than close.

Jos

no my point was that most of console apps i used if double clicked they just blink once and nothing happens until i give them a command with batch file or so, i kinda thought that was something i might have to look into (or not) :). just in case i wanted to know that there is such option.

For example console app called nircmdc.exe (NirCmd v2.20

Copyright © 2003 - 2008 Nir Sofer ) does nothing unless it receives a command like "help" so it would display list of supported commands (am sure u know what am talking about).

In any case thanks for answers

Edited by almostnotstupid
Link to comment
Share on other sites

@ almostnotstupid

A console application can do pretty much whatever a normal GUI application can do. In fact a GUI application can also spawn a console. Most console applications are based on commandline parameter handling, so if you just run them they just show some info and exit.

Now that I think about it, a console application can create a GUI, too (maybe not in AutoIt, but in a compiled language it should ? too tired to try it right now)

Link to comment
Share on other sites

Now that I think about it, a console application can create a GUI, too (maybe not in AutoIt, but in a compiled language it should ? too tired to try it right now)

Sure you can!

#AutoIt3Wrapper_Change2CUI=y
#include <GUIConstants.au3>
If $cmdline[0]=0 Then
    $title="Default Title"
Else
    $title=$cmdline[1]
EndIf
$Form1 = GUICreate($title, 633, 454, 193, 125)
$Button1 = GUICtrlCreateButton("Button1", 24, 224, 121, 49, 0)
$Button2 = GUICtrlCreateButton("Button2", 152, 224, 121, 57, 0)
$Button3 = GUICtrlCreateButton("Button3", 288, 224, 105, 33, 0)
$Slider1 = GUICtrlCreateSlider(48, 32, 561, 33)
GUISetState(@SW_SHOW)

Opt("GUIOnEventMode",1)
GUICtrlSetOnEvent ($Button1,"Button1")
GUICtrlSetOnEvent ($Button2,"Button2")
GUICtrlSetOnEvent ($Button3,"Button3")
GUICtrlSetOnEvent ($Slider1,"Slider1")
GUISetOnEvent($GUI_EVENT_CLOSE,"Close")
While 1
sleep(1000)
WEnd

Func Button1()
    ConsoleWrite("Button1"&@CRLF)
EndFunc
Func Button2()
    ConsoleWrite("Button2"&@CRLF)
EndFunc
Func Button3()
    ConsoleWrite("Button3"&@CRLF)
EndFunc
Func slider1()
    ConsoleWrite("Slider: "&GUICtrlRead($Slider1)&@CRLF)
EndFunc
Func Close()
    Exit
EndFunc

The first commandline parameter passed will be the GUI title. The script will output to the console whenever a button is pressed, or the slider moved.

Link to comment
Share on other sites

You are looking to try and make a traditional cin and cout console in autoit then? It is possible, but harder than in cpp etc.

there is no "cin" function in autoit, however, if you search you'll find an example of how to use 'FileOpen ("con")' to read what has been written to the console. Thats the hardest bit of it. If you want more info on FileOpen ("con") then search google, I believe its an old VB trick.

Mat

Link to comment
Share on other sites

You are looking to try and make a traditional cin and cout console in autoit then? It is possible, but harder than in cpp etc.

there is no "cin" function in autoit, however, if you search you'll find an example of how to use 'FileOpen ("con")' to read what has been written to the console. Thats the hardest bit of it. If you want more info on FileOpen ("con") then search google, I believe its an old VB trick.

Mat

There are no tricks involved in that. It's a well documented parameter passed to CreateFile function (that is used by AutoIt for FileOpen() function) when you want to open console.

CreateFile <- link, click and read.

Edited by trancexx
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...