This is the mail archive of the cygwin mailing list for the Cygwin project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: lpr works? FAQ in error?


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@gmail.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/


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]