[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: reading from external command
From: |
Peng Yu |
Subject: |
Re: reading from external command |
Date: |
Wed, 30 Mar 2022 18:21:41 -0500 |
I am not sure what you are trying to do. But I see nothing in
/proc/self/task/. Did you assume a particular OS?
$ cat main.sh
#!/usr/bin/env bash
# vim: set noexpandtab tabstop=2:
x=( /proc/self/task/* )
$ ./main.sh
declare -a x=([0]="/proc/self/task/*")
On Wed, Mar 30, 2022 at 6:04 PM Alex fxmbsw7 Ratchev <fxmbsw7@gmail.com> wrote:
>
> bash peng
>
> 28250
> /dev/fd/63
> /dev/fd/63
> 41
> 44
> 44
>
> #!/bin/bash
>
> printf $$\\n
>
> pid() {
> x=( /proc/self/task/* )
> printf %s\\n ${x##*/}
> }
>
> >p
> while read -r x ; do
> printf %s\\n <( pid >>p ; exit 44 )
> done < <( pid >>p ; printf shit\\nbla\\n ; exit 41 )
>
> while read -r p ; do
> wait $p
> echo $?
> done <p
>
>
> On Thu, Mar 31, 2022 at 1:00 AM Lawrence Velázquez <vq@larryv.me> wrote:
> >
> > On Wed, Mar 30, 2022, at 6:32 PM, Peng Yu wrote:
> > > I am not sure how wait for "$!" would work robustly.
> > >
> > > In the following example, it can not get the error in the input.
> > >
> > > $ cat ./main.sh
> > > #!/usr/bin/env bash
> > > # vim: set noexpandtab tabstop=2:
> > >
> > > while read -r x; do
> > > echo <(exit 42)
> > > done < <(
> > > builtin printf '%s\n' a b c
> > > false
> > > )
> > > wait "$!"
> > > echo "$?"
> > > $ ./main.sh
> > > /dev/fd/63
> > > /dev/fd/63
> > > /dev/fd/63
> > > 42
> >
> > Now you've gone and changed the problem by spinning off multiple
> > asynchronous commands at once.
> >
> > I don't know how robust this is, but at a minimum you need to access
> > $! before spawning the asynchronous commands you don't care about:
> >
> > % cat main.bash; echo
> > printf '%s\n' "$BASH_VERSION"
> >
> > {
> > pid=$!
> > while read -r x; do
> > echo <(exit 42)
> > done
> > } < <(builtin printf '%s\n' a b c; exit 99)
> >
> > wait "$pid"
> > echo "$?"
> >
> > % bash main.bash
> > 5.1.16(1)-release
> > /dev/fd/62
> > /dev/fd/62
> > /dev/fd/62
> > 99
> >
> > --
> > vq
--
Regards,
Peng
- Re: reading from external command, (continued)
- Re: reading from external command, Alex fxmbsw7 Ratchev, 2022/03/29
- Re: reading from external command, Chet Ramey, 2022/03/30
- Re: reading from external command, Peng Yu, 2022/03/30
- Re: reading from external command, Alex fxmbsw7 Ratchev, 2022/03/30
- Re: reading from external command, Chet Ramey, 2022/03/30
- Re: reading from external command, Peng Yu, 2022/03/30
- Re: reading from external command, Alex fxmbsw7 Ratchev, 2022/03/30
- Message not available
- Message not available
- Re: reading from external command, Alex fxmbsw7 Ratchev, 2022/03/30
- Re: reading from external command, Lawrence Velázquez, 2022/03/30
- Re: reading from external command, Alex fxmbsw7 Ratchev, 2022/03/30
- Re: reading from external command,
Peng Yu <=
- Re: reading from external command, Alex fxmbsw7 Ratchev, 2022/03/30
- Re: reading from external command, Alex fxmbsw7 Ratchev, 2022/03/31
- Re: reading from external command, Alex fxmbsw7 Ratchev, 2022/03/31
- Re: reading from external command, Chet Ramey, 2022/03/31
- Re: reading from external command, Peng Yu, 2022/03/31
- Re: reading from external command, Alex fxmbsw7 Ratchev, 2022/03/31
- Re: reading from external command, Alex fxmbsw7 Ratchev, 2022/03/31
- Re: reading from external command, Alex fxmbsw7 Ratchev, 2022/03/31
- Re: reading from external command, Alex fxmbsw7 Ratchev, 2022/03/31
- Re: reading from external command, Lawrence Velázquez, 2022/03/31