Topic
IC4NOTICE: developerWorks Community will be offline May 29-30, 2015 while we upgrade to the latest version of IBM Connections. For more information, read our upgrade FAQ.
6 replies Latest Post - ‏2012-11-02T10:58:46Z by Chris_Bruce
Chris_Bruce
Chris_Bruce
14 Posts
ACCEPTED ANSWER

Pinned topic Problem Starting Firefox With URL Containing Ampersand

‏2012-10-25T15:54:27Z |
Hi there,

I'm working on some software that does its calcs. and then, using the HOST external routine, starts up a new Firefox browser window passing the OSM URL and the relevant Lat. and Lon. parameters, e.g.
http://www.openstreetmap.org/?lat=52.1917&lon=-1.7073&zoom=12

However nothing from the first ampersand onwards appears in the Firefox address bar, and Firefox just displays the last OSM map view viewed in Firefox, regardless of the actual Lat. in the address bar. Have tried executing the full command (i.e. that issued by my software) from the command prompt in the "DOS window", e.g...
"C:\Program Files\Mozilla Firefox\firefox.exe" -new-tab http://www.openstreetmap.org/?lat=52.1917&lon=-1.7073&zoom=12
and the error messages I get are
'lon' is not recognized as an internal or external command, operable program or batch file.
'zoom' is not recognized as an internal or external command, operable program or batch file.

So it seems to me that WinXP is doing some parsing of the parameter string being passed to Firefox and only actually passing the "lat" parameter to Firefox.

I tried escaping the ampersands with %26 and the whole parameter string then gets through to Firefox but the OSM server (or Firefox?) seems not to recognise the escaped ampersands, thereby displaying the last map shown but not the one requested. I've tried with a semicolon as an alternative delimiter (which, I believe, is supposed to be a valid delimiter) and also the comma, but they just display the last map shown as described above. I've also tried enclosing the URL in double quotes ("); this works OK and as expected in the WinXP command line window but when issued via the HOST or PIPE commands, or via AP100 (same thing really!), I get the following messages in the interpreter window:
'C:\Program' is not recognized as an internal or external command, operable program or batch file.
'lon' is not recognized as an internal or external command, operable program or batch file.
'zoom' is not recognized as an internal or external command, operable program or batch file.

Regular URLs without the ampersand, e.g. an OSM tile URL (http://tile.openstreetmap.org/12/2028/1349.png), work fine.

It seems the required ampersand in the query parameter is tripping me up via WinXP! Any ideas on a resolution? Ta!

Running APL2/2 SL19 on WinXP.
Updated on 2012-11-02T10:58:46Z at 2012-11-02T10:58:46Z by Chris_Bruce
  • Nancy Wheeler
    Nancy Wheeler
    59 Posts
    ACCEPTED ANSWER

    Re: Problem Starting Firefox With URL Containing Ampersand

    ‏2012-10-25T18:27:35Z  in response to Chris_Bruce
    Hi Chris,

    When you use the HOST function (which uses AP 100) or the )HOST system command, or AP 100 directly, you are actually opening a new DOS command shell under the covers. So, any rules about charater parsing, fonts used, etc. are the same rules that would apply if you typed the command in a DOS command prompt. Any characters that DOS might intepret as delimiters (like spaces) or action characters that mean something to DOS need to be surrounded by quotes to protect them from being "seen" by DOS. Ampersand is definitely a character that means something to DOS.

    Unless I am misunderstanding, I believe you said if you used double quotes it worked. So that is the explanation for why.

    I hope this helps.

    Regards,
    Nancy Wheeler
    APL Products and Services
    • Chris_Bruce
      Chris_Bruce
      14 Posts
      ACCEPTED ANSWER

      Re: Problem Starting Firefox With URL Containing Ampersand

      ‏2012-10-26T16:11:21Z  in response to Nancy Wheeler
      Hi there Nancy,

      The command does indeed work from the regular "DOS" command prompt when the URL is enclosed in regular double quotes ("), but does not work when the same string is passed through the HOST command (or via a shared variable with AP100). The error messages I'm getting in the interpreter window are:
      'C:\Program' is not recognized as an internal or external command, operable program or batch file.
      'lon' is not recognized as an internal or external command, operable program or batch file.
      'zoom' is not recognized as an internal or external command, operable program or batch file.

      It seems to me that something is happening to the string between my function, the HOST command and the underthecovers "DOS" command prompt. I've tried various combinations of quoting/double quoting the URL and parts of the URL, as well as escaping the ampersands as described in the OP. I eventually had a last-ditch try at double-quoting the whole string, as well as the URL...and it works via the HOST command! E.g.
      ""C:\Program Files\Mozilla Firefox\firefox.exe" -new-tab "http://www.openstreetmap.org/?lat=52.1917&lon=-1.7073&zoom=12""

      Interestingly this does NOT work from the regular "DOS" command prompt, but does, as I say, via HOST, whereas
      "C:\Program Files\Mozilla Firefox\firefox.exe" -new-tab "http://www.openstreetmap.org/?lat=52.1917&lon=-1.7073&zoom=12"
      (whole string NOT in double quotes) DOES work from the regular "DOS" command prompt, but does NOT via HOST.

      Hmmmmmm!

      Anyway, my problem now solved, but I think there remains an issue here.

      Have a great weekend...
      • Nancy Wheeler
        Nancy Wheeler
        59 Posts
        ACCEPTED ANSWER

        Re: Problem Starting Firefox With URL Containing Ampersand

        ‏2012-10-26T20:07:42Z  in response to Chris_Bruce
        Hi Chris,

        I am stumped. I don't understand why that extra set of double quotes is required around the outside, but only when there are parameters (i.e. if you just call firefox with no parameters, just the one set of quotes around the whole thing is enough.)

        Obviously the shell started by AP 100 is different than a DOS command prompt in some ways, but I don't know exactly what the rules are. We use a C api, system, to start the shell, but what little documentation I can find on it does not specify any details.

        I am glad you figured out a way to get it working.

        Nancy Wheeler
      • SystemAdmin
        SystemAdmin
        65 Posts
        ACCEPTED ANSWER

        Re: Problem Starting Firefox With URL Containing Ampersand

        ‏2012-10-31T14:11:39Z  in response to Chris_Bruce
        BTW Bruce,

        The reason your expression does not work in a DOS command prompt is because by the time you are in the command prompt environment, you are already running CMD.EXE. You are not passing arguments to CMD.EXE; rather, you are responding to prompts displayed by CMD.EXE.

        If you tried to run CMD.EXE from inside the DOS command prompt window, you would need the extra quotation marks.

        David Liebtag
        • Chris_Bruce
          Chris_Bruce
          14 Posts
          ACCEPTED ANSWER

          Re: Problem Starting Firefox With URL Containing Ampersand

          ‏2012-11-02T10:58:46Z  in response to SystemAdmin
          Hi there David,

          Many thanks for the explanation: all clear now!

          Chris
  • SystemAdmin
    SystemAdmin
    65 Posts
    ACCEPTED ANSWER

    Re: Problem Starting Firefox With URL Containing Ampersand

    ‏2012-10-31T13:31:43Z  in response to Chris_Bruce
    Chris,

    AP 100 and the )HOST command use the C runtime library's system() routine. system() in turn uses the CMD.EXE command processor. For information about how to pass parameters to CMD.EXE, please consult this URL:

    http://technet.microsoft.com/en-us/library/6ec588db-31a9-4a73-a970-65a2c6f4abbe

    (If that link does not work, open Windows Help and Support, search for CMD, select Command Reference Overview, and select CMD.)

    Your problem is happening because you have spaces in the path to FireFox.exe and ampersands in the URL passed to FireFox. You need to surround those elements with double quotes. Also, because CMD.EXE strips the first and last quotes around the entire command, you need to add another pair of quotes. This works for me on my 64 bit Windows 7 system:

    CMD←'""C:\Program Files (x86)\Mozilla Firefox\firefox.exe" -new-tab http://www.openstreetmap.org/?lat=52.1917"&lon=-1.7073&zoom=12""'
    HOST CMD
    0

    Hope this helps.

    David Liebtag