help-bash
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: reading from external command


From: Alex fxmbsw7 Ratchev
Subject: Re: reading from external command
Date: Fri, 1 Apr 2022 02:06:15 +0200

you probably want a middle step

you run cmds, with <( .. ) and inside <( .. ) you print ( or so ) the pid,
and additional information related, eg after the command parse the pid and
do according actions

On Fri, Apr 1, 2022 at 2:04 AM Alex fxmbsw7 Ratchev <fxmbsw7@gmail.com>
wrote:

> here with coproc as transmittler instead of a temp file
>
> bash peng2.
>
> pid 15200 exit 4
> pid 15201 exit 1
> pid 15202 exit 2
> pid 15203 exit 3
>
>
> #!/bin/bash
>
>  p() {
> printf $BASHPID\\n >&${mix[1]}
>  }
>
>   coproc mix \
>  while read -r in ; do
> [[ $in == [!0-9] ]] && exec printf %d\\n ${pids[@]} ||
> pids+=( $in )
>  done
>
>  while read -r r ; do
> : <( p ; exit $r )
>  done < <( p ; printf 1\\n2\\n3\\n ; exit 4 )
>
>  for p in $( printf q\\n >&${mix[1]} ; cat <&$mix ) ; do
> wait $p
> printf 'pid %d exit %d\n' $p $?
>  done
>
> exit
>
> On Fri, Apr 1, 2022 at 1:52 AM Alex fxmbsw7 Ratchev <fxmbsw7@gmail.com>
> wrote:
> >
> > sorry again i try..
> >
> > bash peng2
> >
> > pid 14608 exit 4
> > pid 14609 exit 1
> > pid 14610 exit 2
> > pid 14611 exit 3
> >
> >
> > cat peng2
> >
> > #!/bin/bash
> >
> >  p() {
> > printf $BASHPID\\n >>/tmp/ap
> > }
> >
> > >/tmp/ap
> >
> >  while read -r r ; do
> > : <( p ; exit $r )
> >  done < <( p ; printf 1\\n2\\n3\\n ; exit 4 )
> >
> >  while read -r p ; do
> > wait $p
> > printf 'pid %d exit %d\n' $p $?
> >  done </tmp/ap
> >
> > rm -f /tmp/ap
> >
> > On Fri, Apr 1, 2022 at 1:45 AM Alex fxmbsw7 Ratchev <fxmbsw7@gmail.com>
> wrote:
> >>
> >> i did
> >>
> >> with printf $BASHPID
> >>
> >> bye
> >>
> >> On Fri, Apr 1, 2022 at 1:41 AM Peng Yu <pengyu.ut@gmail.com> wrote:
> >>>
> >>> I don't get how to modify the while-loop (with unnamed pipes in the
> >>> body) to get the exit code in the loop input unnamed pipe. Could you
> >>> make it clear by showing a working example? Thanks.
> >>>
> >>> On 3/31/22, Chet Ramey <chet.ramey@case.edu> wrote:
> >>> > On 3/30/22 6:32 PM, Peng Yu wrote:
> >>> >> I am not sure how wait for "$!" would work robustly.
> >>> >
> >>> > You have to capture $! before it can be overwritten by another
> command. For
> >>> > instance, you can assign it to another variable.
> >>> >
> >>> >> In the following example, it can not get the error in the input.
> >>> >
> >>> > Because you didn't do that.
> >>> >
> >>> > --
> >>> > ``The lyf so short, the craft so long to lerne.'' - Chaucer
> >>> >                ``Ars longa, vita brevis'' - Hippocrates
> >>> > Chet Ramey, UTech, CWRU    chet@case.edu
> http://tiswww.cwru.edu/~chet/
> >>> >
> >>>
> >>>
> >>> --
> >>> Regards,
> >>> Peng
>


reply via email to

[Prev in Thread] Current Thread [Next in Thread]