Double Quotes!

Got a LiveCode personal license? Are you a beginner, hobbyist or educator that's new to LiveCode? This forum is the place to go for help getting started. Welcome!

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller

Post Reply
stoavio
Posts: 43
Joined: Sun Jun 30, 2013 2:09 am

Double Quotes!

Post by stoavio » Sat Jul 06, 2013 6:30 am

Hi all,

I'm throwing in the towel on this one. After over an hour of trying different combinations to get this to work, I simply cannot figure it out.

I am trying to execute this command using get shell and put it in a variable. The command is:

Code: Select all

ipconfig /all | find "Host Name"&ipconfig /all | find "IP Address"&ipconfig /all | find "Subnet Mask"&ipconfig /all | find "DNS Servers"
As you can see, this is already concatenated and is done this way so I can store the output from everything in one variable.

The double quotes are throwing me. I understand this is what the quote constant is for but I can't seem to figure out the proper syntax for executing this command. I have had a variety of errors but the latest one is:

Code: Select all

'"Host Name"' is not recognized as an internal or external command,
operable program or batch file.
Can someone help? I've already lost 90 minutes of my life to something I'm sure is ridiculously simple. I just need to see it once! :)

wsamples
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 264
Joined: Mon May 18, 2009 4:12 am

Re: Double Quotes!

Post by wsamples » Sat Jul 06, 2013 6:57 am

It often helps to post the entire code, in your case including the shell("<command to run>") in order to make sure the advice you receive addresses your issue.

Can you simply replace the double quotes in your command with single quotes? This typically works and LiveCode is not confused because the single quotes have no meaning to it, thus you can wrap the command with the required "..." and quote as necessary within the command using single quotes.
Last edited by wsamples on Sat Jul 06, 2013 7:09 am, edited 1 time in total.

wsamples
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 264
Joined: Mon May 18, 2009 4:12 am

Re: Double Quotes!

Post by wsamples » Sat Jul 06, 2013 7:05 am

In using the quote constant you need to be certain to add the " in the right places as you build the sting and confusion is very common in the beginning.

Example:

"this is a quoted "string" containing a quoted section"

becomes:

"this is a quoted" && quote & string & quote && "containing a quoted section"

The & concatenates two strings while && concatenates with an added space. Notice that we must fully quote the two sections of the original string which flank the section being quoted with constants.

stoavio
Posts: 43
Joined: Sun Jun 30, 2013 2:09 am

Re: Double Quotes!

Post by stoavio » Sat Jul 06, 2013 7:20 am

Hi wsamples.

I am happy to post the code. I did try using just the single quotes inside of "..." and the command prompt does not interpret the command correctly. In the following code I have attempted to use single quotes just so you can see what I was trying to accomplish.

Code: Select all

on menuPick pItemName
   hide group "Validate Settings"
   switch pItemName 
      case "Validate Settings"
         Global ipconfig
         show group "Validate Settings"
         set the hideconsolewindows to true 
         get shell("ipconfig /all | find 'Host Name'&ipconfig /all | find 'IP Address'&ipconfig /all | find 'Subnet Mask'&ipconfig /all | find 'DNS Servers'")
         put it into ipconfig
         set the itemDel to ":"
         
         //check host name
         if "ALOHABOH" is in ipconfig then
            put "ALOHABOH" into fld "Computer Name"
            set foregroundColor of fld "Computer Name" to "#2c9303"
         else 
            put item 1 of ipconfig into fld "Computer Name"
            set foregroundColor of fld "Computer Name" to "#e72b00"
            set textStyle of fld "Computer Name" to "bold"
         end if 
         
         //check IP address
         if "192.168.1.100" is in ipconfig then 
            put "192.168.1.100" into fld "IP Address"
            set foregroundColor of fld "IP Address" to "#2c9303"
         else
            put item 13 of ipconfig into fld "IP Address"
            set foregroundColor of fld "IP Address" to "#e72b00"
            set textStyle of fld "IP Address" to "bold"
         end if
         //check subnet mask
         if "255.255.255.0" is in ipconfig then 
            put "PASS" into fld "Subnet Mask"
            set foregroundColor of fld "Subnet Mask" to "#2c9303"
         else
            put "FAIL" into fld "Subnet Mask"
            set foregroundColor of fld "Subnet Mask" to "#e72b00"
            set textStyle of fld "Subnet Mask" to "bold"
         end if
         //check primary DNS
         if "208.67.222.222" is in ipconfig then 
            put "PASS" into fld "Primary DNS"
            set foregroundColor of fld "Primary DNS" to "#2c9303"
         else
            put "FAIL" into fld "Primary DNS"
            set foregroundColor of fld "Primary DNS" to "#e72b00"
            set textStyle of fld "Primary DNS" to "bold"
         end if
         //check secondary DNS
         if "208.67.220.200" is in ipconfig then 
            put "PASS" into fld "Secondary DNS"
            set foregroundColor of fld "Secondary DNS" to "#2c9303"
         else
            put "FAIL" into fld "Secondary DNS"
            set foregroundColor of fld "Secondary DNS" to "#e72b00"
            set textStyle of fld "Secondary DNS" to "bold"
         end if
         break
      case "Restore Data"
         hide group "Validate Settings"
         break
   end switch
end menuPick
Although Livecode isn't reporting any errors, the return from the command line is attached. Unfortunately the single quote method doesn't appear to work in this situation.
Attachments
ipconfig.jpg
ipconfig.jpg (28.47 KiB) Viewed 4869 times

dave_probertGA6e24
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 328
Joined: Mon Dec 05, 2011 5:34 pm
Contact:

Re: Double Quotes!

Post by dave_probertGA6e24 » Sat Jul 06, 2013 7:22 am

try either:

Code: Select all

"ipconfig /all | find 'Host Name'&ipconfig /all | find 'IP Address'&ipconfig /all | find 'Subnet Mask'&ipconfig /all | find 'DNS Servers' "
or

Code: Select all

"ipconfig /all | find " &quote& "Host Name" &quote& "&ipconfig /all | find " &quote& "IP Address" &quote& "&ipconfig /all | find " &quote& "Subnet Mask" &quote& "&ipconfig /all | find " &quote& "DNS Servers" & quote
or

Code: Select all

"ipconfig /all | find \"Host Name\"&ipconfig /all | find \"IP Address\"&ipconfig /all | find \"Subnet Mask\"&ipconfig /all | find \"DNS Servers\" "
see if they work.

Cheers,
Dave
Coding in the Sun - So much Fun.
Visit http://electronic-apps.info for released App information.

stoavio
Posts: 43
Joined: Sun Jun 30, 2013 2:09 am

Re: Double Quotes!

Post by stoavio » Sat Jul 06, 2013 7:36 am

dave_probertGA6e24 wrote:try either:

Code: Select all

"ipconfig /all | find 'Host Name'&ipconfig /all | find 'IP Address'&ipconfig /all | find 'Subnet Mask'&ipconfig /all | find 'DNS Servers' "
or

Code: Select all

"ipconfig /all | find " &quote& "Host Name" &quote& "&ipconfig /all | find " &quote& "IP Address" &quote& "&ipconfig /all | find " &quote& "Subnet Mask" &quote& "&ipconfig /all | find " &quote& "DNS Servers" & quote
or

Code: Select all

"ipconfig /all | find \"Host Name\"&ipconfig /all | find \"IP Address\"&ipconfig /all | find \"Subnet Mask\"&ipconfig /all | find \"DNS Servers\" "
see if they work.

Cheers,
Dave
Dave, the second one worked! Thanks man.

I appreciate you guys helping me out. I was hoping to get your option 3 to work since it is considerably less code. I will keep playing with it but at least now it is working.

Thanks again! :)

Post Reply