There is actually a documented if little-known standard for escaping double quotes inside of double quotes for Win32 command lines. Programs that are written in C or use Microsoft's routine for parsing command lines into command arguments will follow that standard. Unfortunately, not all programs, even including programs provided by Microsoft, use Microsoft's code for parsing command lines into arguments nor even follow Microsoft's document rules.

Note that cmd.exe is still in the picture in most cases so not following Microsoft's rules can get you into minor trouble. You can produce a command that is incapable of receiving certain argument values. That is, if you want one of the things that cmd.exe takes care of for you (<, >, |, &, ^, etc.) included in a command-line argument, then you need to quote it in a way that cmd.exe recognizes. That way of quoting it would also need to be compatible with however the particular program chooses to parse its command line.

Anyway, the way you escape quotes inside of double quotes on Win32 command lines is to preceed them with a backslash. Unlike shell quoting, you can't just throw a double quote into the middle of an argument to start quoting there.

The specification is incomplete (lots of "behaviors that are undefined") and the implementation is at least a bit perverse which makes it appear quite buggy when one so quickly runs into the unspecified cases. The implementation may even be actually buggy for some cases that are within the specified limits, but I'm not aware of any such clear bugs. Quoting MS documentation:

Microsoft C/C++ startup code uses the following rules when interpreting arguments given on the operating system command line:

There's also a library routine that does this parsing that can be used by programs not written in C, though I didn't spend the time trying to remember or find the name of it.

- tye        


In reply to Re^8: quoting issue with system command (Win32 standard) by tye
in thread quoting issue with system command by lomSpace

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.