CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: Beginner:
"perl -e ..." not working in Windows DOS but works in cygwin on Windows

 



anotherperlnoob
Novice

Apr 30, 2015, 8:15 AM

Post #1 of 4 (2153 views)
"perl -e ..." not working in Windows DOS but works in cygwin on Windows Can't Post

Hello,
perl -e is not working in DOS but works in cygwin (both run on a Windows 7 machine).

When I run the following command in a DOS box


Code
perl -e 'print "Hello, Wrox!\n"'


I get the following error message:


Code
Can't find string terminator "'" anywhere before EOF at -e line 1.


When I run the same command in cygwin, I get the expected output:


Code
Hello, Wrox!


What's going on here? In Windows I'm using strawberry perl:


Code
c:\Users\J\Documents\code\perl>perl -v 

This is perl 5, version 18, subversion 2 (v5.18.2) built for MSWin32-x86-multi-thread-64int


FWIW, it appears to be something to do with quotes, e.g. if I strip the print argument down to a single character and reverse the quotes:


Code
c:\Users\J\Documents\code\perl>perl -e 'print "x"' 
Can't find string terminator "'" anywhere before EOF at -e line 1.

c:\Users\J\Documents\code\perl>perl -e "print "x""

c:\Users\J\Documents\code\perl>perl -e "print 'x'"
x
c:\Users\J\Documents\code\perl>


Thanks in advance for any help given!


anotherperlnoob
Novice

Apr 30, 2015, 8:20 AM

Post #2 of 4 (2152 views)
Re: [anotherperlnoob] "perl -e ..." not working in Windows DOS but works in cygwin on Windows [In reply to] Can't Post

Ah, I have found the reason why...it was on the next page of the book!

For anybody interested, it's a known bug.

http://perldoc.perl.org/perlfaq3.html#Why-don't-Perl-one-liners-work-on-my-DOS%2fMac%2fVMS-system%3f


Laurent_R
Veteran / Moderator

Apr 30, 2015, 10:01 AM

Post #3 of 4 (2149 views)
Re: [anotherperlnoob] "perl -e ..." not working in Windows DOS but works in cygwin on Windows [In reply to] Can't Post

Under DOS, you must use double quote marks for the one-liner, so you can't put double quotes inside the one liner. But this should work:

Code
perl -e "print 'x';"

If you need quoting with interpolation:

Code
perl -e "print qq{x\n};"



anotherperlnoob
Novice

Apr 30, 2015, 1:45 PM

Post #4 of 4 (2144 views)
Re: [Laurent_R] "perl -e ..." not working in Windows DOS but works in cygwin on Windows [In reply to] Can't Post

Thanks, Laurent.

 
 


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives