The basic Microsoft C argument processing is that you put double quotes around anything to make it a single argument. Backslash is only special if it is followed by a double quote. So \ is just \ but \" becomes a literal " character, but this is only reliable if done within double quotes. So \\" becomes a backslash followed by a close-quote. \\\" becomes backslash followed by literal quote.

So you want something like:

for( @args ) { if( /[\s"^*?%<>|&]/ ) { s#(\\*)"#$1$1\\"#g; $_= '"' . $_ . '"'; } }

Perhaps with more special characters in the first match.

Update: Oops, I was missing one backslash in my replacement. I had $1$1" when I needed $1$1\\", and we should probably avoid adding quotes if the argument is already surrounded by quotes, at least by default.

- tye        


In reply to Re^2: The Evil Embedded Space (system(@list)) by tye
in thread The Evil Embedded Space by Intrepid

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.