in reply to Quotable Quotes

In your second example,

But, when run at a DOS prompt, the command: C:\>"echo hello" produces '"echo hello"' is not recognized as an internal or external command, operable program or batch file.
Why is there an expectation that Perl is involved at all? It looks like you threw a string in double quotes at cmd.exe.

If you simply: C:\>echo hello you get: hello because echo is a DOS internal command.

Perhaps your original example didn't need the double quotes?

C:\>perl -e "print STDERR `echo hello`"; produces hello

and I've found that when I wanted double-quotes in my on-liners on Windows, I needed (ready for absurdity?) triple double-quotes.

C:\>perl -e "print STDERR `echo """hello"""`"; produces "hello"


I humbly seek wisdom.

Replies are listed 'Best First'.
Re^2: Quotable Quotes
by b4swine (Pilgrim) on Sep 07, 2007 at 16:01 UTC
    It appears to me that everyone is missing the point. Perhaps I was too verbose in my question, so let me be terse this time.

    Ignore all the echo example, that was just to illustrate a point. My real question is just this one:

    print STDERR `"My Echo.pl"`; print STDERR `"My Echo (v1).pl"`;
    The first line works. The second doesn't. Why?

    The behavior is consistent. Any file name with a parenthesis does not work. Others seem to work just fine.

    Yes I know, I can rewrite things (eg. `perl "My Echo (v1).pl"`). My question still is: Why?

      I think I've reproduced your problem in my environment. Triple double-quotes doesn't solve it:

      C:\chas_sandbox>copy con "My Echo.pl" print "hello, world\n"; ^Z 1 file(s) copied. C:\chas_sandbox>copy con "My Echo (v1).pl" print "hello, world\n"; ^Z 1 file(s) copied. C:\chas_sandbox>"My Echo (v1).pl" hello, world C:\chas_sandbox>"My Echo.pl" hello, world C:\chas_sandbox>perl -e "print STDERR `"My Echo.pl"`;" Can't find string terminator "`" anywhere before EOF at -e line 1. C:\chas_sandbox>perl -e "print STDERR `"""My Echo.pl"""`;" hello, world C:\chas_sandbox>perl -e "print STDERR `"My Echo (v1).pl"`;" Can't find string terminator "`" anywhere before EOF at -e line 1. C:\chas_sandbox>perl -e "print STDERR `"""My Echo (v1).pl"""`;" 'My' is not recognized as an internal or external command, operable program or batch file.

      It's obviously getting to the cmd shell, since the not recognized as an internal or external command is from cmd.

      per Sandy's message, below, it's definitely the ()'s that are messing you up. And it's cmd that doesn't like them, not Perl.

      I know you're still asking "why?" but here's another tack for a work-around:

      C:\chas_sandbox>dir /x "My Echo (v1).pl" Volume in drive C has no label. Volume Serial Number is D425-A27D Directory of C:\chas_sandbox 09/07/2007 04:22 PM 25 MYECHO~2.PL My Echo (v1).pl 1 File(s) 25 bytes 0 Dir(s) 28,821,581,824 bytes free C:\chas_sandbox>perl -e "print STDERR `MYECHO~2.PL`;" hello, world C:\chas_sandbox>

      I've used dir /x to get the short name and called the script using the shortname between the backticks.


      I humbly seek wisdom.

        Here's lots of inconsistent behavior, all of which (I think) can be blamed on cmd.exe

        C:\chas_sandbox>"My Echo (v1).pl" hello, world C:\chas_sandbox>cmd /c "My Echo (v1).pl" 'My' is not recognized as an internal or external command, operable program or batch file. C:\chas_sandbox>cmd /c " "My Echo (v1).pl"" hello, world C:\chas_sandbox>cmd /c ""My Echo (v1).pl"" hello, world C:\chas_sandbox>perl -e "print STDERR ` """My Echo (v1).pl"""`;" hello, world C:\chas_sandbox>perl -e "print STDERR `""" """My Echo (v1).pl""""""`;" '" "My' is not recognized as an internal or external command, operable program or batch file. C:\chas_sandbox>


        I humbly seek wisdom.
      Maybe the '(' symbol gives some special meaning .I'm nt sure!!!

      The world is so big for any individual to conquer