Jump to content
Sign in to follow this  
microbious

how to make console application

Recommended Posts

microbious

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

Share this post


Link to post
Share on other sites
TurionAltec

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.

Share this post


Link to post
Share on other sites
microbious

awesome thanks

ill try it ASAP (as soon as i think of my first console app :) )

Share this post


Link to post
Share on other sites
picaxe

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

Share this post


Link to post
Share on other sites
Jos

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

Visit the SciTE4AutoIt3 Download page for the latest versions  - Beta files                                How to post scriptsource        Forum Rules
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Share this post


Link to post
Share on other sites
microbious

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

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

Share this post


Link to post
Share on other sites
Jos

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


Visit the SciTE4AutoIt3 Download page for the latest versions  - Beta files                                How to post scriptsource        Forum Rules
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Share this post


Link to post
Share on other sites
monoceres

Not running a console application from the command line makes absolutely no sense.


Broken link? PM me and I'll send you the file!

Share this post


Link to post
Share on other sites
microbious

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

Share this post


Link to post
Share on other sites
TurionAltec

Not running a console application from the command line makes absolutely no sense.

If it's an interactive one, or one which doesn't immediately terminate and it could.

Share this post


Link to post
Share on other sites
Inverted

@ 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)

Share this post


Link to post
Share on other sites
TurionAltec

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.

Share this post


Link to post
Share on other sites
Mat

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

Share this post


Link to post
Share on other sites
trancexx

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

♡♡♡

.

eMyvnE

Share this post


Link to post
Share on other sites
Mat

Never knew that, though I thought it was documented somewhere. It's very useful to use, but in autoit its both shorter and easier to use inputboxs + other dialogs, so I have never really looked into it.

Share this post


Link to post
Share on other sites
TurionAltec

It's a trick as compared to say ConsoleRead which you'd expect to work, but doesn't.

Here's a thread about using the FileOpen("con") method in Autoit:

http://www.autoitscript.com/forum/index.php?showtopic=79275&st=0&p=571658&#entry571658

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  

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.