Friedrich Posted February 27, 2008 Share Posted February 27, 2008 I am working on an AutoIt program with two components: a compiled script and an external INI file with parameters that can be modified by the user. One of the parameters is a part of the command line and I am looking for a way to move this section from the AutoIt script to the INI file, so that users can modify the command line parameter, if necessary.If I specify the command line directly in the AutoIt script, the compiled program works:$dofile = $CmdLine[1]I tried to specify the command line in the INI file but it is not recognized by the AutoIt script. This is the relevant section in the INI file:[Editor]dofile = $CmdLine[1]This is the line in the AutoIt script that refers to the INI file ($ini is the path to the INI file):$dofile = IniRead($ini,"Editor","dofile","$CmdLine[1]")I have two problems. First, the "dofile" key is ignored and instead the script refers to the default value "$CmdLine[1]". Second, the default value is evaluated as "[1]", presumably because $CmdLine is read as a non-existing variable. All other parameters in the INI file are recognized without problems.Many thanks for any advice you can give. I would be happy to provide additional information if the above is not clear. Link to comment Share on other sites More sharing options...
SpookMeister Posted February 27, 2008 Share Posted February 27, 2008 Can you make a reproduction script/sample to show where you a having trouble? Much easier to answer questions when we have some code to look at. [u]Helpful tips:[/u]If you want better answers to your questions, take the time to reproduce your issue in a small "stand alone" example script whenever possible. Also, make sure you tell us 1) what you tried, 2) what you expected to happen, and 3) what happened instead.[u]Useful links:[/u]BrettF's update to LxP's "How to AutoIt" pdfValuater's Autoit 1-2-3 Download page for the latest versions of Autoit and SciTE[quote]<glyph> For example - if you came in here asking "how do I use a jackhammer" we might ask "why do you need to use a jackhammer"<glyph> If the answer to the latter question is "to knock my grandmother's head off to let out the evil spirits that gave her cancer", then maybe the problem is actually unrelated to jackhammers[/quote] Link to comment Share on other sites More sharing options...
PsaltyDS Posted February 27, 2008 Share Posted February 27, 2008 If you want to read the INI file, with the command line parameter as the default, just take the quotes off the variable reference:$dofile = IniRead($ini,"Editor", "dofile", $CmdLine[1])oÝ÷ Øû¶)àªê-zÆ«¢éÝÛn®wا¶¥×«j[-®)à¡ú®¢Ý7è).)ÞÖ«¨¶z-jö«¦åz·z·§qæ(¹Ê.Ü+×ë¢{^Û?ºÚ oj¸nW¢Ø^ ÒW°ØZºÚ"µÍ[UÜ]J ÌÍÚ[K ][ÝÑY]Ü][ÝË ][ÝÙÙ[I][ÝË ÌÍÐÛY[VÌWJ But it doesn't mean anything to write a literal string like "$CmdLine[1]" into the file. Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law Link to comment Share on other sites More sharing options...
Friedrich Posted February 27, 2008 Author Share Posted February 27, 2008 The quotes around $CmdLine[1] were indeed part of the problem, thanks for pointing that out. However, the "dofile" key is still ignored and instead the default value $CmdLine[1] is used. I know this because editing this part of the INI file has no effect although it works for other parameters (not included in the example below). How can I modify the AutoIt script or INI file to make sure the "dofile" parameter from the INI file is used?To provide more information, the script links a text editor to the Stata statistical package. It copies the path of the file that is currently being edited to the clipboard and pastes it to Stata for subsequent processing. The original script is described on my website (look at Script 1).The core of the program consists of commands that copy and paste the path and filename from a text editor to Stata. These commands can be condensed as follows. $CmdLine[1], which is the source of my problem, contains the path and filename.AutoIt script that works (called from a text editor, no INI file required):; Copy path to current file in editor $dofile = $CmdLine[1] ; Paste file path ClipPut("do " & '"' & $dofile & '"') Send("^v" & "{Enter}")AutoIt script that does not work as expected (called from a text editor, INI file required):; Path to INI file $ini = @ScriptDir & "\rundolines.ini" ; Copy path to current file in editor $dofile = IniRead($ini,"Editor","dofile",$CmdLine[1]) ; Paste file path ClipPut("do " & '"' & $dofile & '"') Send("^v" & "{Enter}")INI file:[Editor] ; Path to text file that is passed to AutoIt dofile = $CmdLine[1] Link to comment Share on other sites More sharing options...
SpookMeister Posted February 27, 2008 Share Posted February 27, 2008 Use ConsoleWrite or MsgBox's to validate the information that you are reading and writing to/from the ini file. I.E. ; Path to INI file $ini = @ScriptDir & "\rundolines.ini" ; Copy path to current file in editor $dofile = IniRead($ini,"Editor","dofile",$CmdLine[1]) ; Paste file path ;ClipPut("do " & '"' & $dofile & '"') ;Send("^v" & "{Enter}") MsgBox(0,"Output","Output=" & $dofile) [u]Helpful tips:[/u]If you want better answers to your questions, take the time to reproduce your issue in a small "stand alone" example script whenever possible. Also, make sure you tell us 1) what you tried, 2) what you expected to happen, and 3) what happened instead.[u]Useful links:[/u]BrettF's update to LxP's "How to AutoIt" pdfValuater's Autoit 1-2-3 Download page for the latest versions of Autoit and SciTE[quote]<glyph> For example - if you came in here asking "how do I use a jackhammer" we might ask "why do you need to use a jackhammer"<glyph> If the answer to the latter question is "to knock my grandmother's head off to let out the evil spirits that gave her cancer", then maybe the problem is actually unrelated to jackhammers[/quote] Link to comment Share on other sites More sharing options...
PsaltyDS Posted February 27, 2008 Share Posted February 27, 2008 Your INI file is still wrong. The entry "dofile=$CmdLine[1]" in the INI is silly.It doesn't do any good at all to put "$CmdLine[1]" in an INI file. The text "$CmdLine[1]" from the INI file will NOT be replaced with contents of the array variable $CmdLine[1].The default value from IniRead() is only returned if the Key referenced does not exist.If the key exists, but has no value, a null value will be returned, not the default.So, if your dofile key exists at all, the contents of $CmdLine[1] will not be returned.Try your IniRead() like this to test what I'm telling you:$dofile = IniRead($ini,"Editor","NonExistentKey",$CmdLine[1]) Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law Link to comment Share on other sites More sharing options...
Friedrich Posted February 28, 2008 Author Share Posted February 28, 2008 Thanks for the responses. I have concluded that it is not possible to specify the command line parameter ($CmdLine[1], $CmdLine[2], or something else) in the INI file. Instead, the parameter has to be hard coded in the AutoIt script. $CmdLine[1] seems to cover most text editors but the script may have to be modified depending on the editor that is used. Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now