Re: output redirection with process substitution asynchronous?

2009-12-06 Thread pjodrr
On Dec 5, 4:45 pm, pk  wrote:
> pjodrr wrote:
> > Hi
>
> > On Dec 4, 7:58 pm, pk  wrote:
> >> What's wrong with
>
> >> seq 4 | while read line; do echo "$(date): $line"; done
>
> > it creates a subshell
>
> uh...where do you think your original
>
> >(while read line; do echo "$(date): $line"; done)
>
> runs?

in my original example the "seq 4" runs in the current shell
while here the command runs in a subshell.

  Peter


Re: output redirection with process substitution asynchronous?

2009-12-06 Thread pjodrr
On Dec 5, 3:51 pm, DennisW  wrote:
> On Dec 5, 3:14 am, pjodrr  wrote:
>
>
>
> > Hello,
>
> > On Dec 4, 8:18 pm, DennisW  wrote:
>
> > > It works for me. Does it not for you? If you're asking why not do it,
> > > then the answer is "why call an external program unnecessarily?".
>
> > > Sorry, by the way, I missed what you were doing with the file
> > > descriptor on my first read. What is it that you're trying to
> > > accomplish? Are you doing this only to number the lines or is either
> > > seq or the while loop a stand-in for something else?
>
> > the seq was only an example for demonstration.
> > here is another example that shows what I mean:
>
> > $ exec 3> >(while read line; do echo "tag: $line"; done)
> > $ seq 4 >&3
> > tag: 1
> > tag: 2
> > tag: 3
> > tag: 4
>
> > $ exec 3> >(while read line; do echo "$(date): $line"; done)
> > $ seq 4 >&3
> > $ Sat Dec  5 10:11:25 CET 2009: 1
> > Sat Dec  5 10:11:25 CET 2009: 2
> > Sat Dec  5 10:11:25 CET 2009: 3
> > Sat Dec  5 10:11:25 CET 2009: 4
>
> > while in the first example the prompt returns after the
> > command completes, the prompt returns immediately
> > in the second example.
>
> > thanks for your attention,
>
> >   Peter
>
> Your example here:
>
> $ exec 3> >(while read line; do echo "tag: $line"; done)
> $ seq 4 >&3
>
> just executes too quickly to exhibit this behavior. Try this and it
> will do it, too:
>
> $ exec 3> >(while read line; do for i in {1..1}; do :; done; echo
> '.'; done)

this results in:

malloc: ../bash/subst.c:4198: assertion botched
realloc: start and end chunk sizes differ
last command: exec 3> >(while read line; do for i in {1..1}; do :;
done; echo '.'; done)
Aborting...Aborted

but I see your point of course.

> $ seq 4 >&3
>
> I think the thing to remember is that doing this is like running
> something in the background with "&". So, yes, it's going to be
> asynchronous.

thanks for your explanation.  Is there any way to avoid this
behaviour?
There is probably no way to wait for the completion, is there?
Other than like this:

fifo=$(mktemp -u) || exit
mkfifo $fifo || exit
trap "rm -f $fifo" 0
trap exit 1 2 15
while read line; do echo "$(date): $line"; done < $fifo &
prefix_pid=$!
seq 4 > $fifo
wait $prefix_pid

Or how would you accomplish this?

  Peter


Re: output redirection with process substitution asynchronous?

2009-12-06 Thread pk
pjodrr wrote:

> in my original example the "seq 4" runs in the current shell
> while here the command runs in a subshell.

It would be nice if you explained what it is you're attempting to do, rather 
than ask for a solution for what you're thinking would do that.