This is the mail archive of the
cygwin
mailing list for the Cygwin project.
Re: Trouble Sending Printer Codes from Perl to Printer
- From: ericblake at comcast dot net (Eric Blake)
- To: David Vergin <dvergin at igc dot org>, cygwin at cygwin dot com
- Date: Fri, 01 Jul 2005 00:13:08 +0000
- Subject: Re: Trouble Sending Printer Codes from Perl to Printer
> <BASH TRANSCRIPT>
> $ echo -en "hello\nworld"
> hello
> world
> dvergin@GatewayM275 /c/bin
> $ #Good! The basic approach works on the command line.
> #Control codes are interpreted and no trailing newline.
> #So I'll try the same thing from perl letting the echo
> # command convert the control char.
> # (Note different approach farther down)
>
> $ perl -e 'system(q/echo -en "hello\nworld"/)'
> -en hello\nworld
>
> dvergin@GatewayM275 /c/bin
> $ #Ack! The -en option is treated as text to be echoed.
Ah - the classic /bin/sh is not /bin/bash. system() uses /bin/sh, and ash
unfortunately doesn't recognize -en as an argument to echo. POSIX
recommends using printf, not echo, when you want more control over
what system() outputs:
$ perl -e 'system(q/printf "hello\0\nworld"/)' | od -tx1
0000000 68 65 6c 6c 6f 00 0a 77 6f 72 6c 64
0000014
Aha - \0 worked, \n was interpreted, and no trailing newline.
And by the way, this is not cygwin specific - any use of \ escape sequences
as an argument to echo is inherently non-portable across different shells.
--
Eric Blake
--
Unsubscribe info: http://cygwin.com/ml/#unsubscribe-simple
Problem reports: http://cygwin.com/problems.html
Documentation: http://cygwin.com/docs.html
FAQ: http://cygwin.com/faq/