Jump to content

Making CmdLine work inside of quotes


Recommended Posts

I am trying to run an executable on a file that is given as a parameter of the AutoIt script. "auto3.exe myScript.au3 someFilePath"

Quote

Run( 'myExecutable.exe $CmdLine[1]' )

The issue is the quotes need to be there since Run takes one parameter, but with them there autoIt recognizes the parameter var as a String. 

Anyone have tips on how to make this work? or a better way to pass the parameter in?

Link to post
Share on other sites
1 hour ago, FrancescoDiMuro said:

You can use ExpandVarStrings option too :)

Hi Francesco :)

As far as I know, ExpandVarStrings does not work with arrays :

Example :

Opt("ExpandVarStrings", 1) ; 0=don't expand(default), 1=do expand
If $CMDLINE[0] Then
    ConsoleWrite("ExpandVar : $CMDLINE[1]$" & @CRLF)
    ConsoleWrite("Normal    : " & $CMDLINE[1] & @CRLF)
Else
    ConsoleWrite("Error : no CMDLine parameters passed" & @CRLF)
EndIf

see :

 

Musashi-C64.png

"In the beginning the Universe was created. This has made a lot of people very angry and been widely regarded as a bad move."

Link to post
Share on other sites

@llssff :

Here is a test script that considers the answers from @Luke94 und @FrancescoDiMuro :

(use clock.au3 as a parameter)

Opt("ExpandVarStrings", 1) ; 0=don't expand(default), 1=do expand

; Example : uses the interpreter AutoIt3.exe (as macro) :
Local $sMyExecutable = @AutoItExe
Local $sMyScript

; Check, if a commandline parameter was passed (otherwise an error will occur).
If $CMDLINE[0] Then
    ; Example : path to the script : ..\AutoIt3\Examples\GUI\Advanced\ :
    ; ==> Use clock.au3 as CMDLine[1] (to quit the clock, use ESC)
    $sMyScript = StringRegExpReplace(@AutoItExe, "(?i)AutoIt3.exe$", "") & "Examples\GUI\Advanced\" & $CMDLINE[1]


    ; ==> Comment out one of the variants at a time :
    ; Variant 1 : start 'normal' :
    Run($sMyExecutable & ' "' & $sMyScript &'"')

    ; Variant 2 : use 'ExpandVarStrings' :
    ;Run($sMyExecutable & ' "$sMyScript$"')
Else
    ConsoleWrite("Error : no CMDLine parameters passed" & @CRLF)
EndIf

 

Musashi-C64.png

"In the beginning the Universe was created. This has made a lot of people very angry and been widely regarded as a bad move."

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
  • Recently Browsing   0 members

    No registered users viewing this page.

×
×
  • Create New...