Jump to content

Adding Command Line Parameter


Recommended Posts

Hi guys,

I don't understand how to add to a autoit .exe a command line interface The help this time don't help me like expeted.

Example simple code:

Func Test()
MsgBox(0,0,"test")
EndFunc

If i run it nothing happens, it's normal.

But how to add a command line parameter like:

C:UsersUsername>test.exe /name "True"
Completed Successfully

And see the MsgBox with the variable text?

Please provide some example

Thanks for support :oops:

Edited by johnmcloud
Link to comment
Share on other sites

The help file perfectly describes how passing parameters to an AutoIt exe works.

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2024-07-28 - Version 1.6.3.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to comment
Share on other sites

Try this and you will see how it works:

MsgBox(64, "Passed Parameters", $CmdLine[0] & " parameters have been passed to this script:")
For $i = 1 To $CmdLine[0]
    MsgBox(64, "Passed Parameters", "Parameter " & $i & ": " & $CmdLine[$i])
Next
Edited by water

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2024-07-28 - Version 1.6.3.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to comment
Share on other sites

Who passes the parameters to the script - a user or another script?

Only if a user passes the parameters something like "/name" makes sense.

To write something to the console you have to compile the script as CUI not as GUI (Ctrl+F7 in Scite and set "Create CUI instead of GUI EXE")

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2024-07-28 - Version 1.6.3.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to comment
Share on other sites

My script don't have a GUI, select a file with FileOpenDialog and create a special shortcut with parameter. My intention was to delete that shortcut by cmd, like:

test.exe /delete test

In autoit will be:

FileDelete(@DesktopDir & "" & $var & ".ink")

The $var is equal to "test"

I don't like the CUI option, i'm not set a responce on CMD, i'll make a simpy MsgBox

Edited by johnmcloud
Link to comment
Share on other sites

If every parameter consists of a name (like "/name") and the value (like "asd") you could parse the parameters like this:

#AutoIt3Wrapper_Change2CUI=y
$sTitle = "Test Script"
If Mod($CmdLine[0], 2) <> 0 Then Exit MsgBox(16, $sTitle, "Invalid number of parameters! has to be a multiple of 2!")
If $CmdLine[0] = 0 Then Exit MsgBox(16, $sTitle, "No parameters passed!")
For $i = 1 To $CmdLine[0] Step 2
    If $CmdLine[$i] = "/name" Then MsgBox(64, "Passed Parameters", "/name is " & $CmdLine[$i+1])
Next
ConsoleWrite("Finished!")

Open a cmd window and enter "test.exe /name asdf".

You will get a MsgBox and the text "Finished!" on the console.

Edited by water

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2024-07-28 - Version 1.6.3.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to comment
Share on other sites

Just for know, that script write something on cmd console? Because i can't see nothing after MsgBox ( i have compiled it )

You have make this:

#AutoIt3Wrapper_Change2CUI=y

It's for write something on cmd?

Edited by johnmcloud
Link to comment
Share on other sites

Yes. Open a DOS console window and run your test exe with parameters "/name ads"

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2024-07-28 - Version 1.6.3.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to comment
Share on other sites

I get the following display after clicking "OK":

C:Temp>"test.exe" /name asd

Finished!

C:Temp>

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2024-07-28 - Version 1.6.3.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to comment
Share on other sites

I'm not, as you can see. I'm on Windows 7 x64, try to compile even x86 / x64, no "Finished" output, i have click ok but nothing:

C:UsersUSERNAME>"C:UsersUSERNAMEDesktopasd.exe" /name asd
C:UsersUSERNAME>
Edited by johnmcloud
Link to comment
Share on other sites

You have to click "OK" on the MsgBox because the text is written to the console at the end of the script.

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2024-07-28 - Version 1.6.3.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to comment
Share on other sites

I can reproduce this behaviour when I removed line "#AutoIt3Wrapper_Change2CUI=y" from the script.

Make sure this line is at the top of your script and you will get "Finished!" on the console.

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2024-07-28 - Version 1.6.3.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to comment
Share on other sites

Nothing

Posted Image

Yes, is on top:

#AutoIt3Wrapper_Change2CUI=y
$sTitle = "Test Script"
;~ If Mod($CmdLine[0], 2) <> 0 Then Exit MsgBox(16, $sTitle, "Invalid number of parameters! has to be a multiple of 2!")
;~ If $CmdLine[0] = 0 Then Exit MsgBox(16, $sTitle, "No parameters passed!")
For $i = 1 To $CmdLine[0] Step 2
If $CmdLine[$i] = "/name" Then MsgBox(64, "Passed Parameters", "/name is " & $CmdLine[$i+1])
Next
ConsoleWrite("Finished!")
Edited by johnmcloud
Link to comment
Share on other sites

Did you verify that "#AutoIt3Wrapper_Change2CUI=y" is at the top of your script?

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2024-07-28 - Version 1.6.3.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to comment
Share on other sites

Do you have the full SciTE package installed?

Btw, you don't need "#AutoIt3Wrapper_Change2CUI=y" when you don't need the CMD output!

Compile this and start the exe with some arguments:

#include <array.au3>
If $CmdLine[0] Then
_ArrayDisplay($CmdLine)
EndIf

If will display your arguments. You can analyse the arguments and do what ever you want.

Br,

UEZ

Edited by UEZ

Please don't send me any personal message and ask for support! I will not reply!

Selection of finest graphical examples at Codepen.io

The own fart smells best!
Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!
¯\_(ツ)_/¯  ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ

Link to comment
Share on other sites

UEZ, yes.

Water say that :oops: You have an alternative?

Work only in this case:

#Region ;**** Directives created by AutoIt3Wrapper_GUI ****
#AutoIt3Wrapper_UseUpx=n
#AutoIt3Wrapper_Change2CUI=y
#AutoIt3Wrapper_Res_requestedExecutionLevel=asInvoker
#EndRegion ;**** Directives created by AutoIt3Wrapper_GUI ****
$sTitle = "Test Script"
;~ If Mod($CmdLine[0], 2) <> 0 Then Exit MsgBox(16, $sTitle, "Invalid number of parameters! has to be a multiple of 2!")
;~ If $CmdLine[0] = 0 Then Exit MsgBox(16, $sTitle, "No parameters passed!")
For $i = 1 To $CmdLine[0] Step 2
    If $CmdLine[$i] = "/name" Then MsgBox(64, "Passed Parameters", "/name is " & $CmdLine[$i+1])
Next
ConsoleWrite("Finished!")

Really strange, if i enable UPX not work, If i removed requestedExecutionLevel=asInvoker not work...

I'm using 3.3.8.0 with full scite installed

Edited by johnmcloud
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

×
×
  • Create New...