Jump to content

Need Quotes around "String Variable String"


Recommended Posts

Hello - First off, I've done a ton of searching for this and just can't seem to find a similiar example. I'm sure it will be basic for you guys, so I thank you for your patience in advance.

OK, so I'm re-writing a script that installed one print driver to one that installs multiple print drivers using arrays to enumerate each one. I'm having a problem transforming

$hostname = '"print123.mydomain.com"'
into string & variable & string format with double quotes around the whole line.

My goal is to end up with a formatted string exactly like this (quotes included) "print123.mydomain.com" where 123 is sourced from a variable.

I've tried using single quotes, but the two options end up like this:

$host[$i] = '"print" & $number[$i] & ".mydomain.com"'
Which evaluates to: "print" & $number[$i] & ".mydomain.com"

And

$host[$i] = '"print"' & $number[$i] & '".mydomain.com"'
Which evaluates to: "print"123".mydomain.com"

Any help would be greatly appreciated!

-Ken

Link to comment
Share on other sites

  • Developers

..Thanks for not making fun of me!

why?

I understands it can be confusing in the beginning and you become "blind" for the obvious... but I make no promises for the future :)

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Link to comment
Share on other sites

  • 2 months later...

$host[$i] = '"print' & $number[$i] & '.mydomain.com"'

:D

Hi!

Could somebody help me with this:

I am constructing the argument String like this:

CODE
For $i = 2 to $CmdLine[0] Step 1

$argumentString = $argumentString & " " & $CmdLine[$i]

Next

and then I do this:

CODE
If FileExists($oldProgram) And $CmdLine[1] = "-cmd" Then

MsgBox(0, "try", $oldProgram & " " & $CmdLine[1] & $argumentString)

where

CODE
$oldProgram = "C:\Program Files\Some Program Name"
The program expects arguments in this fashion: ProgramName.exe -cmd "argument List" (with the double quote)

I am not able to make this work.

Thanks,

Raj

Link to comment
Share on other sites

MsgBox(0, 'try', $oldProgram & ' -cmd "' & $argumentString & '"')

If $CmdLine[1] match "-cmd" then just use "-cmd", for simplicity.

Also, you can double double quotes ;]"""" just to get one double quotes into double quoted string lol or use single quote and it'll look clearer.

Hi

Thanks for your reply.

Could you tell me why it is not working when I run it using the Run command:

CODE
If FileExists($oldProgram) And $CmdLine[1] = "-cmd" Then

$commandString = '"' & $oldProgram & '"' & ' -cmd "' & $argumentString & '"'

Run(@ComSpec & " /c " & $commandString, "", @SW_HIDE)

I also tried it without the @ComSpec but it does not work.

Thanks,

Raj

Link to comment
Share on other sites

$commandString = $oldProgram &  '" -cmd "' & $argumentString & '"'
Run(@ComSpec & ' /k "' & $commandString)

Test this one, see what you get in the command line, the title actually. If it doesn't work then you'll need to check if -cmd thing is correct. Also, verify the condition is evaluated to true because otherwise either $oldProgram doesn't contain path to existing file or $CmdLine[1] is not equal to -cmd.

Link to comment
Share on other sites

Won't it be because the program name has a space in there? You need to put quotes around the program name in that case I think ...

Link to comment
Share on other sites

Won't it be because the program name has a space in there? You need to put quotes around the program name in that case I think ...

Thanks for your replies. That worked.

Could you tell me what is the difference between the /k option and the /c option to @ComSpec.

The code seems to work with the /k option but not with the /c option.

Thanks,

Raj

Link to comment
Share on other sites

/c = close

/k = keep

Edit: I think it's not what made it to work. It's just so you see what you're sending to the command line. It could be much easier to just output ti the console using ConsoleWrite and see how it's look like.

Edited by Authenticity
Link to comment
Share on other sites

/c = close

/k = keep

Edit: I think it's not what made it to work. It's just so you see what you're sending to the command line. It could be much easier to just output ti the console using ConsoleWrite and see how it's look like.

There was a bug in my code. I had an extra lead space in the $argumentString

I fixed it.

Thanks,

Raj

Link to comment
Share on other sites

i am sorry but just being curious, why dont i see anyone suggesting chr(34)

the simples way out i use for such a situation is

" & chr(34) & "Stringtobewrappedinquoteshere" & chr(34)
I use it often but there are other methods that will also work

George

Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.

Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.***

The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number.

Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else.

"Old age and treachery will always overcome youth and skill!"

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...