water Posted November 26, 2010 Share Posted November 26, 2010 A question for the gurus on this forum Our ServiceDesk tool is going to call a compiled AutoIT script. It passes parameters in the format as PowerShell gets them (I was told). Its either -xxxx=1234or -yyyy="String value" What do you think is the best way to parse the parameter string and set the variables in AutoIt? So in my script the variable $xxxx should have the value 1234 and $yyyy should be "String value". I haven't coded anything yet but would be grateful for any idea on how to start. Thanks! My UDFs and Tutorials: Spoiler UDFs:Active Directory (NEW 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - WikiExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example ScriptsOutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - WikiOutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - DownloadOutlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - WikiPowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - WikiTask Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki Standard UDFs:Excel - Example Scripts - WikiWord - Wiki Tutorials:ADO - WikiWebDriver - Wiki Link to comment Share on other sites More sharing options...
UEZ Posted November 26, 2010 Share Posted November 26, 2010 What about this method? #AutoIt3Wrapper_UseUpx=n #AutoIt3Wrapper_UseX64=n #AutoIt3Wrapper_Change2CUI=y #include <Array.au3> If Not $CmdLine[0] Then Exit ConsoleWrite("No parameter found!" & @CRLF) Dim $variables[1] For $i = 1 To $CmdLine[0] $val = StringRegExp( $CmdLine[$i], "-(.*)=(.*)", 3) Assign($val[0], $val[1], 2) _ArrayAdd($variables, String($val[0])) Next $variables[0] = UBound($variables) - 1 For $i = 1 To $variables[0] ConsoleWrite($variables[$i] & "=" & Eval($variables[$i]) & @CRLF) Next This is just a basic solution without checks whether the parameters are really like -XXXX=YYYY Br, 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 More sharing options...
water Posted November 26, 2010 Author Share Posted November 26, 2010 Hi UEZ, vielen Dank! I had a quick test and it's working perfect. Even embedded blanks are handled correctly: C:\TEMP>test.exe -xxx="Dies ist ein Test" -yyy=123 -zzz=Normal xxx=Dies ist ein Test yyy=123 zzz=Normal Thanks a lot! My UDFs and Tutorials: Spoiler UDFs:Active Directory (NEW 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - WikiExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example ScriptsOutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - WikiOutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - DownloadOutlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - WikiPowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - WikiTask Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki Standard UDFs:Excel - Example Scripts - WikiWord - Wiki Tutorials:ADO - WikiWebDriver - Wiki Link to comment Share on other sites More sharing options...
UEZ Posted November 26, 2010 Share Posted November 26, 2010 Hi UEZ, vielen Dank! I had a quick test and it's working perfect. Even embedded blanks are handled correctly: C:\TEMP>test.exe -xxx="Dies ist ein Test" -yyy=123 -zzz=Normal xxx=Dies ist ein Test yyy=123 zzz=Normal Thanks a lot! Bitte sehr! Gruß, 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 More sharing options...
water Posted November 26, 2010 Author Share Posted November 26, 2010 (edited) One small question: Your RegExp splits at the last "=" in the parameter. Is it possible to split at the first "="? The parameter -sOU="OU=Spezial_Policy_Stufe_0,OU=MyCompany,OU=User_Accounts,DC=microsoft,DC=com" now returns $val[0] = "sOU=OU=Spezial_Policy_Stufe_0,OU=Konzern,OU=User_Accounts,DC=company,DC" $val[1] = "com" but I need $val[0] = "sOU" $val[1] = "OU=Spezial_Policy_Stufe_0,OU=Konzern,OU=User_Accounts,DC=company,DC=com" Is this possible? Thanks in advance! Edited October 12, 2019 by water My UDFs and Tutorials: Spoiler UDFs:Active Directory (NEW 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - WikiExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example ScriptsOutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - WikiOutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - DownloadOutlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - WikiPowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - WikiTask Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki Standard UDFs:Excel - Example Scripts - WikiWord - Wiki Tutorials:ADO - WikiWebDriver - Wiki Link to comment Share on other sites More sharing options...
Tvern Posted November 26, 2010 Share Posted November 26, 2010 Untested, but try to replace: "-(.*)=(.*)" with "-(.*?)=(.*)"The question mark will make that group look for the smallest match, instead of the largest. Link to comment Share on other sites More sharing options...
water Posted November 26, 2010 Author Share Posted November 26, 2010 Hi Tvern, thanks a lot for the fast reply! Your solution works fine! Have a nice weekend! My UDFs and Tutorials: Spoiler UDFs:Active Directory (NEW 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - WikiExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example ScriptsOutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - WikiOutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - DownloadOutlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - WikiPowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - WikiTask Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki Standard UDFs:Excel - Example Scripts - WikiWord - Wiki Tutorials:ADO - WikiWebDriver - Wiki 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