GoogleDude Posted January 14, 2019 Share Posted January 14, 2019 I found the below code on the forum a while back when searching around. I have a script that uses the below code that when the compiled script runs with the /Name= switch is reads the part after the = in order to get the value and set the value as $var or in the below case $GetCMDLineValue. It works great if there is no spaces in the value specified. Normally I would put quotes around the value and off it goes but no matter how I format it I only gets the leftside of the first space. There may be a metter way of doing this but this is what I came up with so far based on what I read and found! How can I make it so I can pass /Name="This is a Value" and have $GetCMDLineValue get set as "This is a Value"? $GetCmdLine = $CmdLineRaw $GetCmdLine1 = '/Name=' Global $GetCmdLineValue = StringMid($GetCmdLine, (StringInStr($GetCmdLine, $GetCmdLine1) + StringLen($GetCmdLine1) + 0), StringInStr($GetCmdLine, " ", 0, 1, StringInStr($GetCmdLine, $GetCmdLine1) + StringLen($GetCmdLine1)) - (StringInStr($GetCmdLine, $GetCmdLine1) + StringLen($GetCmdLine1))) MsgBox(0,"",$GetCmdLineValue) Thanks in advance, ~GD Link to comment Share on other sites More sharing options...
Subz Posted January 14, 2019 Share Posted January 14, 2019 Depends if you would have any other switches but if you're only using "/Name" you could use something like: $sCmdLine = StringStripWS(StringReplace($CmdLineRaw, "/Name=", ""), 3) MsgBox(4096, "Switch", $sCmdLine) Link to comment Share on other sites More sharing options...
GoogleDude Posted January 14, 2019 Author Share Posted January 14, 2019 (edited) Thanks, Forgot to mention sorry. Yes there are other switches about 4 to be exact. They all work as long as the values individually doesnt contains spaces. Edited January 14, 2019 by GoogleDude Link to comment Share on other sites More sharing options...
Subz Posted January 14, 2019 Share Posted January 14, 2019 I use the following UDF when parsing comand lines, just don't include "=" sign and you can use something like: /Name "Some really long text" #include <CmdLine.au3> Global $sName = _CmdLine_Get("Name") GoogleDude 1 Link to comment Share on other sites More sharing options...
GoogleDude Posted January 14, 2019 Author Share Posted January 14, 2019 Thank you for that thread. That's even better than my current approach. Thanks again! ~SG Link to comment Share on other sites More sharing options...
FrancescoDiMuro Posted January 14, 2019 Share Posted January 14, 2019 @GoogleDude You can use StringRegExp too #include <Array.au3> #include <StringCostants.au3> Global $strString = '/CmdLine1=Value1 ' & _ '/CmdLine2=Value with spaces ' & _ '/CmdLine3="Value with double quotes"' & _ '/CmdLine4="C:\Users\SomeUser" /CmdLine5s=', _ $strPattern = '(?:\/[^=]+=)([^\/]+)', _ $arrResult $arrResult = StringRegExp($strString, $strPattern, $STR_REGEXPARRAYGLOBALMATCH) _ArrayDisplay($arrResult) Comments: Spoiler (?:): non-capturing group. Everything is inside these group won't be "captured";\/: Literally the character slash. It needs to be escaped, so the backslash character is used to escape it;[^=]+: Everything that is not an equal symbol, with the quantifier 1 or more;=: Literally the equal sign;([^\/]+): capturing group. Everything that is not a slash, with the quantifier 1 or more. Click here to see my signature: Spoiler ALWAYS GOOD TO READ: Forum Rules Forum Etiquette Link to comment Share on other sites More sharing options...
TheSaint Posted January 14, 2019 Share Posted January 14, 2019 You could just use $CmdLineRaw to get the whole, then divide that up yourself using StringSplit etc, if you know what to separate on. Make sure brain is in gear before opening mouth! Remember, what is not said, can be just as important as what is said. Spoiler What is the Secret Key? Life is like a Donut If I put effort into communication, I expect you to read properly & fully, or just not comment. Ignoring those who try to divert conversation with irrelevancies. If I'm intent on insulting you or being rude, I will be obvious, not ambiguous about it. I'm only big and bad, to those who have an over-active imagination. I may have the Artistic Liesense to disagree with you. TheSaint's Toolbox (be advised many downloads are not working due to ISP screwup with my storage) 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