I have read about "quotes and quote-like operators" in the perlop documentation. I think the problem here is not perl but Microsoft (Update: this is confirmed, see note and solution at bottom).

Double quotes gobbled

When run from perl
print STDERR `"echo hello"`;
produces
hello
But, when run at a DOS prompt, the command:
C:\>"echo hello"
produces
'"echo hello"' is not recognized as an internal or external command, o +perable program or batch file.
It appears that in this case, perl did not send the quotes to DOS.

Double quotes not gobbled

On the other hand, I want to execute a file which has a space in its name. For example I write a file called My Echo.pl which contains simply print "echo\n";

I create a copy of the same file with the name My Echo (v1).pl.

Now I run the following perl program:

print STDERR `"My Echo.pl"`; print STDERR `"My Echo (v1).pl"`;
And the result is
echo 'My' is not recognized as an internal or external command, operable pr +ogram or batch file.

Summary and Question

It appears that when the file name contains a parenthesis, some different kind of interpretation occurs, and the internal double quotes are lost. How can I run "My Echo (v1).pl" (without going to Linux)?

Update: I know that print STDERR `My\\ Echo (v1).pl`; will work, but for my own reasons, I want to use quotes (I don't want to parse the string an find all spaces etc).

Update: The explanation is almost surely given in the answer by Sandy. It is clear that this has nothing to do with perl and is just another weirdness of MSDOS (JAWMS). The cmd.exe drops the quotes under some circumstances. Actually the case in point doesn't match any of the documented circumstances mentioned in the documentation of cmd.exe, but then that is Microsoft. The final proof (as shown by goibhniu is the following DOS output (no perl involved):

C:\>cmd/c "My Echo.pl" echo C:\>cmd/c "My Echo (v1).pl" 'My' is not recognized as an internal or external command, operable program or batch file.

Updated Solution: Just put a space after the last quote, and DOS then does not strip the quotes in its bizzare inconsistent way. Eg: `"dos command with spaces and (parens).pl" ` I wonder if this bug is mentioned at Microsoft.


In reply to Quotable Quotes by b4swine

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.