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: Thu, 31 Mar 2022 01:25:11 +0200

On Thu, Mar 31, 2022, 01:21 Peng Yu <pengyu.ut@gmail.com> wrote:

> I am not sure what you are trying to do. But I see nothing in
> /proc/self/task/. Did you assume a particular OS?
>

to print the shells ( <( .. ) ) pid to storage for wait later
cause $$ isnt and i couldnt remember tje correct var name, ah bashpid
uppercase maybe

$ 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
>


reply via email to

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