delorie.com/archives/browse.cgi   search  
Mail Archives: cygwin/2008/07/23/16:20:49

X-Recipient: archive-cygwin AT delorie DOT com
X-Spam-Check-By: sourceware.org
Message-ID: <f60fe000807231320i38753dc3vc78af6dc6c029cbb@mail.gmail.com>
Date: Wed, 23 Jul 2008 16:20:15 -0400
From: "Mark J. Reed" <markjreed AT mail DOT com>
To: cygwin AT cygwin DOT com
Subject: Re: lpr works? FAQ in error?
In-Reply-To: <103f84ldjk247ihimh4enrpp7tmoc0sgos@4ax.com>
MIME-Version: 1.0
References: <380-2200855974950906 AT cantv DOT net> <loom DOT 20080717T220746-843 AT post DOT gmane DOT org> <g5ov52$9pm$1 AT ger DOT gmane DOT org> <9a498418e4cd1ia8ll54i7eqiehdjmq0m5 AT 4ax DOT com> <ml59841anhmn21j3b0e83mk0hpnonb0rm7 AT 4ax DOT com> <31DDB7BE4BF41D4888D41709C476B6570929B1FA AT NIHCESMLBX5 DOT nih DOT gov> <103f84ldjk247ihimh4enrpp7tmoc0sgos AT 4ax DOT com>
X-Google-Sender-Auth: 02e4646c1eb31a49
X-IsSubscribed: yes
Mailing-List: contact cygwin-help AT cygwin DOT com; run by ezmlm
List-Id: <cygwin.cygwin.com>
List-Unsubscribe: <mailto:cygwin-unsubscribe-archive-cygwin=delorie DOT com AT cygwin DOT com>
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

On Wed, Jul 23, 2008 at 4:00 PM, Wilfried wrote:
> I had tested my script and it worked for me.

That's usually the case.  Most bugs are things the author didn't think of. :)

> I agree that just 5 parameters may be not enough.

Then why use that number? Why use any number of parameters, instead of
just all of them? e.g.

command="$1"
shift
"$command" "$@"

But still, it's not usually a good idea to pass a command to some
other command and have it run it on your behalf; it vastly restricts
the sort of things you can do in that pipeline.  Better to do as Barry
suggested and just run the command directly and pipe its output into
your 'print this' script.

do a whole | bunch of stuff | myprint.sh

done.

> But there is no need to put the sleep command in.
> I had the impression that the script waited until the cygstart command
> was finished.

Yes, but the cygstart command doesn't wait for the command it starts;
it returns to the shell prompt immediately.  So the script might start
Notepad and then delete the file before Notepad even has a chance to
try to load it.

>  But even if not -- Notepad loads the file completely into
> memory and then releases the file handle, so one can delete the file
> while notepad is still open.

...in which case you still end up with a temp file lying around after
you're done with it...

Something like this (untested):

#!/bin/bash
tmp_file="/tmp/cygprint$$"
if (( $# )); then
   exec < <(cat "$@")
fi
unix2dos >"$tmp_file" || { echo >&2 "$0: error writing $tmp_file"; exit 1; }
"$(cygpath -u "$COMSPEC")" /c start /wait notepad.exe /p "$tmp_file"
rc=$?
rm "$tmp_file"
exit $rc


-- 
Mark J. Reed <markjreed AT gmail DOT com>

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