www.delorie.com/archives/browse.cgi   search  
Mail Archives: cygwin/2005/06/30/20:05:54

Mailing-List: contact cygwin-help AT cygwin DOT com; run by ezmlm
List-Subscribe: <mailto:cygwin-subscribe AT cygwin DOT com>
List-Archive: <http://sourceware.org/ml/cygwin/>
List-Post: <mailto:cygwin AT cygwin DOT com>
List-Help: <mailto:cygwin-help AT cygwin DOT com>, <http://sourceware.org/ml/#faqs>
Sender: cygwin-owner AT cygwin DOT com
Mail-Followup-To: cygwin AT cygwin DOT com
Delivered-To: mailing list cygwin AT cygwin DOT com
Date: Thu, 30 Jun 2005 20:05:35 -0400 (EDT)
From: Igor Pechtchanski <pechtcha AT cs DOT nyu DOT edu>
Reply-To: cygwin AT cygwin DOT com
To: Lasse <lasse AT yrk DOT dk>
cc: cygwin AT cygwin DOT com
Subject: Re: Trouble Sending Printer Codes from Perl to Printer
In-Reply-To: <da1vu7$ded$1@sea.gmane.org>
Message-ID: <Pine.GSO.4.61.0506301959130.15034@slinky.cs.nyu.edu>
References: <42C48248 DOT 4090404 AT igc DOT org> <da1vu7$ded$1 AT sea DOT gmane DOT org>
MIME-Version: 1.0

On Fri, 1 Jul 2005, Lasse wrote:

> David Vergin wrote:
> > I'm adapting a working linux program to cygwin. The process has been
> > relatively painless except for this issue which has delayed me way
> > past deadline.
> >
> > I need to output text and printer codes (which may include \000) from
> > a perl program to a printer which may be on a parallel port or a USB
> > port. In the past I have done this on linux using something like the
> > following.
> >
> >     system(qq/echo -en "$data_str" | lpr -oraw/);
> >     ...or whatever
> >
> > That does not work in cygwin. It would work. But on cygwin echo behaves
> > differently in a perl system() command from the way it works from the bash
> > command line.

To answer the original question: system() uses /bin/sh.  On Linux, it's
bash.  On Cygwin, it isn't -- it's ash.  The "echo" builtin of ash doesn't
understand the "-ne" switches, so it just echoes them.  If you want
portable behavior, use '/bin/echo -ne "$data_str"' instead.

To answer the other original question, use the "-l" option for Cygwin's
"lpr" (instead of "-oraw").

> Why would want use echo for this? Just use a piped open directly to lpr:
>
>     open(FH, '| lpr -oraw');
>     print(FH, $data_str);
>     close(FH);
>
> (Error handling left as an exercise to the reader...)
>
> See also: http://www.google.com/search?q=perl+piped+open

Almost right:

open FH, '| lpr -oraw';
print FH $data_str;
close FH;

(parens are optional, but the main thing is that there can't be a comma
after FH in the print statement).

Incidentally, even that's not always needed, since in Cygwin, you should
just be able to write to the printer directly (if you know the name, that
is).
	Igor
-- 
				http://cs.nyu.edu/~pechtcha/
      |\      _,,,---,,_		pechtcha AT cs DOT nyu DOT edu
ZZZzz /,`.-'`'    -.  ;-;;,_		igor AT watson DOT ibm DOT com
     |,4-  ) )-,_. ,\ (  `'-'		Igor Pechtchanski, Ph.D.
    '---''(_/--'  `-'\_) fL	a.k.a JaguaR-R-R-r-r-r-.-.-.  Meow!

"The Sun will pass between the Earth and the Moon tonight for a total
Lunar eclipse..." -- WCBS Radio Newsbrief, Oct 27 2004, 12:01 pm EDT

--
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/

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019