Agreed backslashing embedded double quotes is the easiest way of dealing with things on the command line. However, I'd still like to get a grip on exactly how double-quotes are parsed by CMD.EXE.

One reason is that if you ever have to try and pass a filename that contains spaces to an external program via cmd.exe, especialy if it is one that won't accept forward slashes as path separators, the mess of backslashed backslashes escaping embedded quotes is just so damned messy to get right.

I'm sure that there is some logic to it, even if it is twisted logic. I think the source of the messiness related to the fact that you can quote individual parts of a complete path as well as a whole path.

P:\test>dir d:\"Program Files"\"Apache Group"\* Volume in drive D is Winnt Volume Serial Number is D822-5AE5 Directory of d:\Program Files\Apache Group 31/05/02 17:38 <DIR> . 31/05/02 17:38 <DIR> .. 31/05/02 17:38 <DIR> Apache2 3 File(s) 0 bytes 947,634,176 bytes free

However, that's notth complete story as if you try and pass this into a c program like perl

P:\test>perl pq.pl8 d:\"Program Files"\"Textpad 4"\* (d:"Program) (Files"Textpad 4\*)

You get an almighty mess. Add an extra set of quotes and you get

P:\test>perl pq.pl8 "d:\"Program Files"\"Textpad 4"\*" (d:"Program Files"Textpad) (4\*)

TO achieve the desired result you have to escape the backslashes

P:\test>perl pq.pl8 d:\\"Program Files"\\"Textpad 4"\* (d:\Program Files\Textpad 4\*)

I can't help but think that using backslash as an escape character on a system that has programs that require the backslash be used as the path separator is a terminally (sic) bad idea.

Oh well. Our's is not to reason why......


Examine what is said, not who speaks.
"Efficiency is intelligent laziness." -David Dunham
"Think for yourself!" - Abigail
Hooray!


In reply to Re: Re^4: Windows command line (use \") by BrowserUk
in thread Windows command line by dda

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.