Jump to content

Quotation marks around a $Variable?


 Share

Recommended Posts

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 :idea:

Link to comment
Share on other sites

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 by omikron48
Link to comment
Share on other sites

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 :idea: Thanks again for your help.

Link to comment
Share on other sites

;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 by omikron48
Link to comment
Share on other sites

  • 9 years later...

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 by MrKm
Link to comment
Share on other sites

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...