Hadez Posted April 24, 2010 Posted April 24, 2010 Hi, i was searching for a while about how to have a variable inside quotation marks, as when i add "$variable" as a commandline argument, it is seen as a string. Is there a way to have the variable inside the " "? My code is similar to this: $chkFileNamePath = FileRead($chkMovePath) I need to add the $chkFileNamePath as a commandline parameter. This parameter needs to be inside Quotationmarks. got any ideas as to how i can do this? Thanks alot for your help
omikron48 Posted April 24, 2010 Posted April 24, 2010 (edited) Global $string = "variable" MsgBox(0x2000, "Variable String", "This is how you add a " & $string & " in the middle of a string.") You don't want to put a variable within a string because, under normal conditions, the parser will not evaluate the variable if it's contained within quotes. You can however concatenate however many strings or variables you want into one big string. OR in case you need to include a double quote inside a string, you can either use two double quotes or enclose a double quote with single quotes. Global $string = "variable" MsgBox(0x2000, "Quote Example", "This is how you add a """ & $string & '" in the middle of a string.') Edited April 24, 2010 by omikron48
Hadez Posted April 24, 2010 Author Posted April 24, 2010 Hi mate, thanks for your reply, but im kinda lost with this. Am i right in understanding that instead of giving the commandline the variable, i should process the variable beforehand to make a string and then send that string to commandline? The example im using is this: $chkFileNamePath = FileRead($chkMovePath) $ppMKTLine = $ppMLocation & ' -a ' & $chkFileNamePath & ' -b -c ' & $ppName & ' ' & $ppFileLocation The requirement is that $chkFileNamePath and $ppFileLocation both need to be inside "" so in a perfect world where everything worked,it would look like: $chkFileNamePath = FileRead($chkMovePath) $ppFileLocation = FileRead($NewLinePath) $ppMKTLine = $ppMLocation & ' -a ' & "$chkFileNamePath" & ' -b -c ' & $ppName & ' ' & "$ppFileLocation" If i replace the Variables with a string it runs in command line fine, but then messes up with the "" being seen as a string. Im not too sure how i would make that $ppMKTLine a string value though as the variables by nature would change. Any pointers in the right direction would be more than welcome as im going round in circles Thanks again for your help.
omikron48 Posted April 24, 2010 Posted April 24, 2010 (edited) ;create test text file Global $filename = "C:\_My Test File\message.txt" Global $filehandle = FileOpen($filename, 10) FileWriteLine($filehandle, "Hello world!") FileClose($filehandle) ;what it looks like in commandline MsgBox(0, "Commandline", 'notepad.exe "' & $filename & '"', "") ;open test text file in notepad RunWait('notepad.exe "' & $filename & '"', "") ;clean up test text file FileDelete($filename) In this example, I'm forced to resort to enclosing the actual file path within double quotes in the string value since commandline doesn't like it when your parameter has a whitespace in it (in this case, the folder name). The fastest way to answer your question would be to set Opt for ExpandVarStrings to 1, but that's bad practice to use when it isn't necessary. Edited April 24, 2010 by omikron48
Hadez Posted April 24, 2010 Author Posted April 24, 2010 Nice 1. U solved the problem. It doesnt like to be surrounded by "" but is more than happy with having '"' Nice work around mate. Thanks alot
MrKm Posted May 9, 2019 Posted May 9, 2019 (edited) Sorry to bump an old post 🤐 But I'm curious to know how you actually solve that. I'm caught up in the same fix where I need to surround the variable ,of which a path with spaces, using "" or else the command is interpreted with too many arguments or with a wrong Syntax 😪 Nvm .. Solved by "path_to_prog..\my.exe -convert " & '"' & $Path_variable_with_spaces & '" ' & @ScriptDir & "\output.txt" Edited May 9, 2019 by MrKm AutoIT OCR UDF with OCRSpace
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