[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: output redirection with process substitution asynchronous?
From: |
pjodrr |
Subject: |
Re: output redirection with process substitution asynchronous? |
Date: |
Sun, 6 Dec 2009 00:49:44 -0800 (PST) |
User-agent: |
G2/1.0 |
On Dec 5, 3:51 pm, DennisW <dennistwilliam...@gmail.com> wrote:
> On Dec 5, 3:14 am, pjodrr <pjo...@gmail.com> wrote:
>
>
>
> > Hello,
>
> > On Dec 4, 8:18 pm, DennisW <dennistwilliam...@gmail.com> 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..10000}; 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..10000}; 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
- output redirection with process substitution asynchronous?, pjodrr, 2009/12/04
- Re: output redirection with process substitution asynchronous?, pjodrr, 2009/12/05
- Re: output redirection with process substitution asynchronous?, pk, 2009/12/05
- Re: output redirection with process substitution asynchronous?, pjodrr, 2009/12/06
- Re: output redirection with process substitution asynchronous?, pk, 2009/12/06
- Re: output redirection with process substitution asynchronous?, Marc Herbert, 2009/12/07
- Re: output redirection with process substitution asynchronous?, Greg Wooledge, 2009/12/07
- Re: output redirection with process substitution asynchronous?, Marc Herbert, 2009/12/07
- Message not available
- Re: output redirection with process substitution asynchronous?, DennisW, 2009/12/07
- Message not available
- Re: output redirection with process substitution asynchronous?, pjodrr, 2009/12/08
- Re: output redirection with process substitution asynchronous?, Marc Herbert, 2009/12/08