Search code examples
syntaxparametersparameter-passingautoit

Correct Syntax for running a "Run" with macro.(AutoIt)


I have here a script that runs an exe file and passes a parameter 7 to it.

Run("'C:\test\CONVERTER.exe' 7")

This script above runs perfectly but when I add the macro @ScriptDir, a problem occurs.

Run(@ScriptDir & "'\CONVERTER.exe' 7")

It doesn't pop-up any error but I can see that the script is isn't because there is no icon in the Icon tray. I suspect that it's something about with the syntax. I can't find any documentation about this so I really need help.

Any help is greatly appreciated.


Solution

  • You have to take care of the quoting needed in cmd. Use one of the following:

    Run(@ScriptDir & '\CONVERTER.exe 7')
    Run(@ScriptDir & "\CONVERTER.exe 7")
    

    If you need to quote the path/filename (because of possible spaces) in cmd, you have to quote the complete path/file:

    Run('"' & @ScriptDir & '\CONVERTER.exe" 7')
    

    Attention: Run("'" & @ScriptDir & "\CONVERTER.exe' 7") is valid AutoIt syntax, but doesn't work because the quoting for cmd is wrong (only " allowed)